package com.ktgj.flight.common.qunar;

import cn.hutool.core.lang.Console;
import com.alibaba.fastjson.JSON;
import com.google.common.base.Strings;
import com.ktgj.common.core.enums.EmHelper;
import com.ktgj.common.core.enums.EnumHelper;
import com.ktgj.common.core.utils.*;
import com.ktgj.common.core.utils.StringUtils;
import com.ktgj.common.core.utils.sign.Base64;
import com.ktgj.flight.common.BaseClass;
import com.ktgj.flight.common.linkstar.domain.searchFlight.one.QunarStopInfo;
import com.ktgj.flight.common.ruili.drdomain.BookingContactInfo;
import com.ktgj.flight.common.qunar.domain.*;
import com.ktgj.flight.common.qunar.domain.dto.*;
import com.ktgj.flight.domain.CabinLevel;
import com.ktgj.flight.domain.FlightCabinrule;
import com.ktgj.flight.domain.InterfaceEntity.*;
import com.ktgj.flight.service.IFlightCabinruleService;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.math.BigDecimal;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 去哪儿机票接口
 *
 * @author wyj
 * @create 2021-09-16 13:13
 */
@Service
public class _Qunar extends BaseClass {

    private final Logger logger = LoggerFactory.getLogger(_Qunar.class);

    private final static String CallBack = "http://gc.jsjinfo.cn/bscrm/Ticket/AutoIssue/Callback/FlightNotice.aspx";
    private static String ServerUrl = "http://qae.qunar.com/api/router";
    private final static String AppKey = "a37c85da0b7626a47432d782fee413c5";
    private final static String UserName = "oexyjmn1394";
    private final static String BankCode = EmHelper.EbankCode.PNRPAY.toString();

    /**
     * 支付宝账号
     * 易宝：jingliyang@jsj.com.cn
     * 易生：yuexiaohong@jsj.com.cn
     * 汇付天下：bjjinseshiji
     */
    private final static String AlipayAccount = "bjjinseshiji";//  10025381221  "yijiuecp@163.com";yuexiaohong@jsj.com.cn

    // 分为 youxuan | tehui,youxuan包含赌退改签产品和官网产品，tehui只有官网正规产品
    private String ex_track = "jssj";

    // 往返查询
    private String ex_trackRound = "fxwf";

    //日期格式化 +  1000 ~ 10000之间的随机数
    private String strOnlyCode = data(new Date(), "yyyyMMddHHmmss") + new Random().nextInt(10000) % (10000 - 1000 + 1) + 1000;

    @Autowired
    private IFlightCabinruleService flightCabinruleService;

    /**
     * 机票查询（航班搜索接口）
     *
     * @param moRequest
     * @return
     */
    @Override
    public MoFlightSearchResponse _FlightSearch(MoFlightSearchRequest moRequest) {

        MoFlightSearchResponse response = new MoFlightSearchResponse();
        String strRequestData = "";
        String strResponseData = "";
        Date requestTime = new Date();

        try {
            MoQunar mo = new MoQunar("flight.national.supply.sl.searchflight", requestTime.getTime());

            //应用级参数
            Map<String, String> applyData = new HashMap<>();
            //出发城市代码 一个
            applyData.put("dpt", moRequest.GoSearchWhere.OrgAirport);
            //到达城市代码 一个
            applyData.put("arr", moRequest.GoSearchWhere.DstAirport);
            //查询出发日期 一个
            applyData.put("date", moRequest.GoSearchWhere.DepDate);

            //兼容往返
            if (moRequest.TripType == EnumHelper.TripType.往返.getValue()) {
                mo = new MoQunar("flight.national.supply.round.searchflight", requestTime.getTime());
                logger.info("=======兼容往返：{}========", mo.toString());

                Map<String, String> applyDataRound = new HashMap<>();
                //出发城市代码 一个
                applyDataRound.put("depCity", moRequest.GoSearchWhere.OrgAirport);
                //到达城市代码 一个
                applyDataRound.put("arrCity", moRequest.GoSearchWhere.DstAirport);
                //查询出发日期 一个
                applyDataRound.put("goDate", moRequest.GoSearchWhere.DepDate);
                //回程查询时间
                applyDataRound.put("backDate", moRequest.BackSearchWhere.DepDate);
                //往返查询
                applyDataRound.put("exTrack", ex_trackRound);

                strResponseData = _GetResponseData(mo, applyDataRound, strRequestData);

                if (!StringUtils.isNotEmpty(strResponseData)) {
                    response.ErrorMsg = "接口返回数据为空";
                    return response;
                }
                //往返
                QunarFlightSearchRoundResonse qsResponse = JSON.parseObject(strResponseData, QunarFlightSearchRoundResonse.class);
                if (qsResponse.code != 0) {
                    response.ErrorMsg = qsResponse.message;
                    return response;
                }

                //从数据库里把所有的退改签规则拿到
                List<FlightCabinrule> flightCabinrules = flightCabinruleService.selectFlightCabinRule();
                //从数据库里把所有的仓位等级拿到
                List<CabinLevel> cabinLevels = flightCabinruleService.queryCabinLevelList();
                for (Flightlist flightlist : qsResponse.result.flightList) {

                    TripCroup tcp = new TripCroup();
                    Trip tpGo = new Trip();
                    Trip tpBack = new Trip();

                    tpGo.Cabin = flightlist.pack.cabin.split("_")[0]; //仓位
                    tpGo.FlightNo = flightlist.pack.code.split("_")[0]; //航班号
                    tpGo.OrgAirport = flightlist.go.depAirportCode; //出发机场代码
                    tpGo.DstAirport = flightlist.go.arrAirportCode; //抵达机场代码
                    tpGo.CabinMark = flightlist.pack.minTag; //仓位标识
                    tpGo.cabinType = flightlist.pack.cabinType;
                    tpGo.Price = new BigDecimal(flightlist.pack.minPrice);
                    tpGo.LegNum = 1;

                    tpBack.Cabin = flightlist.pack.cabin.split("_")[1];
                    tpBack.FlightNo = flightlist.pack.code.split("_")[1];
                    tpBack.Price = new BigDecimal(flightlist.pack.minPrice);
                    tpBack.OrgAirport = flightlist.back.depAirportCode;
                    tpBack.DstAirport = flightlist.back.arrAirportCode;
                    tpBack.CabinMark = flightlist.pack.minTag;
                    tpBack.cabinType = flightlist.pack.cabinType;
                    tpBack.LegNum = 2;
                    tcp.ListTrip.add(tpGo);
                    tcp.ListTrip.add(tpBack);

                    response.TripCroupList.add(tcp);

                    List<GoBack> gb = new ArrayList<>();
                    gb.add(flightlist.go);
                    gb.add(flightlist.back);

                    int nm = 0;
                    for (GoBack goBack : gb) {
                        MoFlightInfo finfo = new MoFlightInfo();
                        String dt = moRequest.GoSearchWhere.DepDate; //出发查询日期
                        if (nm == 0) {
                            finfo.LegNum = 1;
                        } else if (nm == 1) {
                            finfo.LegNum = 2;
                            dt = moRequest.BackSearchWhere.DepDate; //回程查询日期
                        }
                        //航班信息
                        finfo.Carrier = goBack.carrier;
                        finfo.DstAirportName = goBack.depAirport;
                        finfo.DstAirport = goBack.depAirportCode;
                        finfo.DepTerm = goBack.depTerminal; //出发机场航站楼
                        finfo.OrgAirportName = goBack.arrAirport;
                        finfo.OrgAirport = goBack.arrAirportCode;
                        finfo.ArrTerm = goBack.arrTerminal;
                        if (!"".equals(goBack.tof) && goBack.tof!=null) {
                            finfo.FuelTax = new BigDecimal(goBack.tof); //燃油费
                        }
                        if (!"".equals(goBack.arf) && goBack.arf!=null) {
                            finfo.AirportTax = new BigDecimal(goBack.arf);//机场建设费
                        }

                        if (goBack.stops) { //是否经停
                            finfo.StopCount = 1;
                            //TODO 经停信息
                        }
                        if (!"".equals(goBack.correct) && goBack.correct !=null) {
                            finfo.PunctualityRate = new BigDecimal(goBack.correct.replace("%", ""));
                        }

                        finfo.flightTimes = goBack.flightTimes; //时长
                        finfo.FlightNo = goBack.flightCode;
                        finfo.IsCodeShare = goBack.codeShare; // 是否共享航班
                        finfo.Carrier = goBack.mainCarrier; //实际承运航班号
                        finfo.Airline = goBack.carrier; //航空公司代码
                        finfo.PlaneStyle = goBack.planeType; //机型
                        if (!"".equals(goBack.distance) && goBack.distance!=null) {
                            finfo.TPM = Integer.valueOf(goBack.distance);
                        }

                        //日期
                        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                        if (!"".equals(goBack.depTime) && goBack.depTime!=null) {
                            finfo.DepDate = format.parse(dt + " " + goBack.depTime);
                        }
                        if (!"".equals(goBack.arrTime) && goBack.arrTime!=null) {
                            finfo.ArrDate = format.parse(dt + " " + goBack.arrTime);
                        }

                        //餐食
                        String mealType = (String) goBack.mealType;


                        if (nm == 0) { //去程
                            MoCabinInfo cinfo = new MoCabinInfo();
                            cinfo.Cabin = tpGo.Cabin;
                            cinfo.CabinMark = tpGo.CabinMark;
                            cinfo.CabinLeftDesc = "座位充足";
                            //cinfo.CabinLevel = EnumHelper.CabinLevel.特惠优选.getValue();

                            for (FlightCabinrule flightCabinrule : flightCabinrules) {
                                if (flightCabinrule.getAirline().equals(finfo.Airline) && flightCabinrule.getCabin().indexOf(cinfo.Cabin.substring(0, 1)) >= 0) {
                                    for (CabinLevel cabinLevel : cabinLevels) {
                                        if (flightCabinrule.getCabinlevel() == cabinLevel.getCabinLevelId()) {
                                            cinfo.BaseCabin = cabinLevel.getCabinLevelType();
                                            cinfo.BaseCabinName = cabinLevel.getCabinLevelName();
                                            break;
                                        }
                                    }
                                    break;
                                }
                            }

                            /*List<FlightCabinrule> cabinrules = flightCabinruleService.queryFlightCabinRule(finfo.Airline, cinfo.Cabin.substring(0,1));
                            if (cabinrules != null && cabinrules.size() > 0) {
                                FlightCabinrule cabinrule = cabinrules.get(0);
                                CabinLevel cabinLevel = flightCabinruleService.queryCabinLevelId(cabinrule.getCabinlevel());
                                cinfo.BaseCabin = cabinLevel.getCabinLevelType();
                                cinfo.BaseCabinName = cabinLevel.getCabinLevelName();
                            }*/

                            cinfo.CallCenterAmountInfo.OrgTicketAmount = tpGo.Price;
                            cinfo.Meal = mealType;

                            finfo.ListCabinInfo.add(cinfo);
                            response.ListGoFlightInfo.add(finfo);

                            /*if (!finfo.ListCabinInfo.stream().anyMatch(item -> item.Cabin.equals(cinfo.Cabin) &&
                                    item.CabinMark.equals(cinfo.CabinMark) &&
                                    item.CallCenterAmountInfo.TicketAmountVip.equals(cinfo.CallCenterAmountInfo.TicketAmountVip))) {
                                finfo.ListCabinInfo.add(cinfo);
                            }
                            if (!response.ListGoFlightInfo.stream().anyMatch(item -> item.FlightNo.equals(finfo.FlightNo) &&
                                    item.OrgAirport.equals(finfo.OrgAirport) && item.DstAirport.equals(finfo.DstAirport) &&
                                    item.DepDate.equals(finfo.DepDate))) {
                                response.ListGoFlightInfo.add(finfo);
                            }*/
                        } else { //返程
                            MoCabinInfo cinfo = new MoCabinInfo();
                            cinfo.Cabin = tpBack.Cabin;
                            cinfo.CabinMark = tpBack.CabinMark;
                            cinfo.CabinLeftDesc = "座位充足";
                            //cinfo.CabinLevel = EnumHelper.CabinLevel.特惠优选.getValue();

                            for (FlightCabinrule flightCabinrule : flightCabinrules) {
                                if (flightCabinrule.getAirline().equals(finfo.Airline) && flightCabinrule.getCabin().indexOf(cinfo.Cabin.substring(0, 1)) >= 0) {
                                    for (CabinLevel cabinLevel : cabinLevels) {
                                        if (flightCabinrule.getCabinlevel() == cabinLevel.getCabinLevelId()) {
                                            cinfo.BaseCabin = cabinLevel.getCabinLevelType();
                                            cinfo.BaseCabinName = cabinLevel.getCabinLevelName();
                                            break;
                                        }
                                    }
                                    break;
                                }
                            }

                            /*List<FlightCabinrule> cabinrules = flightCabinruleService.queryFlightCabinRule(finfo.Airline, cinfo.Cabin.substring(0,1));
                            if (cabinrules != null && cabinrules.size() > 0) {
                                FlightCabinrule cabinrule = cabinrules.get(0);
                                CabinLevel cabinLevel = flightCabinruleService.queryCabinLevelId(cabinrule.getCabinlevel());
                                cinfo.BaseCabin = cabinLevel.getCabinLevelType();
                                cinfo.BaseCabinName = cabinLevel.getCabinLevelName();
                            }*/

                            cinfo.CallCenterAmountInfo.OrgTicketAmount = tpBack.Price;
                            cinfo.Meal = mealType;

                            finfo.ListCabinInfo.add(cinfo);
                            response.ListBackFlightInfo.add(finfo);

                            /*if (!finfo.ListCabinInfo.stream().anyMatch(item -> item.Cabin.equals(cinfo.Cabin) && item.CabinMark.equals(cinfo.CabinMark) &&
                                    item.CallCenterAmountInfo.TicketAmountVip.equals(cinfo.CallCenterAmountInfo.TicketAmountVip))) {
                                finfo.ListCabinInfo.add(cinfo);
                            }

                            if (!response.ListBackFlightInfo.stream().anyMatch(item -> item.FlightNo.equals(finfo.FlightNo) && item.OrgAirport.equals(finfo.OrgAirport) &&
                                    item.DstAirport.equals(finfo.DstAirport) && item.DepDate.equals(finfo.DepDate))) {
                                response.ListBackFlightInfo.add(finfo);
                            }*/
                        }
                        nm++;
                    }
                }

            } else {
                applyData.put("ex_track", ex_track);
                strResponseData = _GetResponseData(mo, applyData, strRequestData);
//                logger.info("======请求响应结果为：{}", strResponseData);

                if (StringUtils.isNotEmpty(strResponseData)) {
                    QunarFlightSearchResonse qsResponse = JSON.parseObject(strResponseData, QunarFlightSearchResonse.class);
                    if (qsResponse.code == 0 && qsResponse.result != null && qsResponse.result.total > 0) {
                        for (Flightinfo flightInfo : qsResponse.result.flightInfos) {

                            MoFlightInfo info = new MoFlightInfo();
                            info.OrgAirport = flightInfo.dpt; //出发机场三字码
                            info.DstAirport = flightInfo.arr; //抵达机场三字码
                            info.DstAirportName = flightInfo.arrAirport; //到达机场
                            info.OrgAirportName = flightInfo.dptAirport; //出发机场
                            info.DepTerm = flightInfo.dptTerminal; //出发机场航站楼
                            info.ArrTerm = flightInfo.arrTerminal; //抵达机场航站楼
                            if (!"".equals(flightInfo.arrTime) && flightInfo.arrTime!=null) {
                                info.ArrDate = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(moRequest.GoSearchWhere.DepDate + " " + flightInfo.arrTime); //到达日期
                            }
                            if (!"".equals(flightInfo.dptTime) && flightInfo.dptTime!=null) {
                                info.DepDate = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(moRequest.GoSearchWhere.DepDate + " " + flightInfo.dptTime);//出发时间
                            }

                            if (flightInfo.stopInfoList != null && flightInfo.stopInfoList.size() > 0) {
                                for (QunarStopInfo qunarStopInfo : flightInfo.stopInfoList) {
                                    info.stopPlace = qunarStopInfo.stopAirportCode;
                                    String depDate = qunarStopInfo.dptDate + " " + qunarStopInfo.dptTime;
                                    String arrDate = qunarStopInfo.arrDate + " " + qunarStopInfo.arrTime;
                                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                                    Date dep = dateFormat.parse(depDate);
                                    Date arr = dateFormat.parse(arrDate);
                                    long diff = dep.getTime() - arr.getTime();
                                    long diffMinutes = diff / (60 * 1000) % 60;
                                    long diffHours = diff / (60 * 60 * 1000) % 24;

                                    String flightTimes = "";
                                    if (diffHours == 0) {
                                        flightTimes = diffMinutes + "分钟";
                                    } else if (diffMinutes == 0) {
                                        flightTimes = diffHours + "小时";
                                    } else if (diffHours != 0 && diffMinutes != 0) {
                                        flightTimes = diffHours + "小时" + diffMinutes + "分钟";
                                    }
                                    info.stopTime = flightTimes;
                                    info.stopDate = depDate;
                                    info.stopEndDate = arrDate;
                                }
                            }

                            info.Cabin = flightInfo.cabin; //仓位
                            info.cabinType = flightInfo.cabinType;
                            if (!"".equals(flightInfo.distance) && flightInfo.distance!=null) {
                                info.TPM = Integer.parseInt(flightInfo.distance); //航程距离
                            }
                            info.flightTimes = flightInfo.flightTimes;//飞行时间
                            info.FlightNo = flightInfo.flightNum; //航班号
                            info.IsCodeShare = flightInfo.codeShare; //是否共享航班
                            info.Carrier = flightInfo.actFlightNum; //共享主飞航班
                            info.Airline = flightInfo.carrier; //航司
                            info.AirportTax = flightInfo.arf; //基建
                            info.FuelTax = flightInfo.tof; //燃油
                            info.StopCount = flightInfo.stopsNum; //经停次数
                            info.PlaneStyle = flightInfo.planetype; //机型
                            info.Airline = flightInfo.carrier; //航司

                            if (flightInfo.stop) {
                                FlightStopEntity flightStopEntity = new FlightStopEntity();
                                ////经停城市三字码
                                flightStopEntity.StopCityCode = flightInfo.stopCityCode;
                                info.ListFlightStop.add(flightStopEntity);
                            }

                            MoCabinInfo cinfo = new MoCabinInfo();
                            cinfo.Cabin = flightInfo.cabin; //仓位
                            cinfo.BaseCabin = flightInfo.cabinType;
                            cinfo.CabinLevel = EnumHelper.CabinLevel.特惠优选.getValue();
                            cinfo.BaseAmount = flightInfo.barePrice; //销售价
                            cinfo.CallCenterAmountInfo.TicketAmount = cinfo.BaseAmount;
                            //cinfo.CallCenterAmountInfo.TicketAmountVip = cinfo.BaseAmount;
                            cinfo.CallCenterAmountInfo.OrgTicketAmount = cinfo.BaseAmount;
                            if (flightInfo.discount != null && flightInfo.discount.intValue() > 0)
                                cinfo.CallCenterAmountInfo.DisCountRate = flightInfo.discount.multiply(new BigDecimal(10));
                            //cinfo.CabinLeft = 9;
                            if (flightInfo.cabinCount.equals("A")) {
                                cinfo.CabinLeftDesc = "座位充足";
                            } else {
                                cinfo.CabinLeftDesc = flightInfo.cabinCount;
                            }
                            if (flightInfo.cabinType.equals("ECONOMY"))
                                cinfo.BaseCabinName = "经济舱";

                            if (flightInfo.tag.indexOf("OPL28") > 0) {
                                //赋值后方便退改签信息使用.
                                cinfo.PassengerAgeLimit = "OPL28";
                                //只允许身份证
                                cinfo.AcceptableIDCardTypeList = "1";
                            }
                            if (flightInfo.tag.indexOf("OPL9") >= 0 || flightInfo.tag.indexOf("CXF1") >= 0 || flightInfo.tag.indexOf("SPL1") >= 0) {
                                cinfo.IsFullReceipt = true;
                            } else {
                                cinfo.IsFullReceipt = false;
                            }
                            String meal = flightInfo.meal ? "Y" : "N";
                            if (meal.equals("Y")) {
                                cinfo.Meal = "有餐食";
                            } else if (meal.equals("N")) {
                                cinfo.Meal = "无餐食";
                            }
                            // 此时是否查询退改签
                            if (!info.ListCabinInfo.stream().anyMatch(item -> item.Cabin.equals(cinfo.Cabin) && item.BaseAmount.equals(cinfo.BaseAmount))) {
                                info.ListCabinInfo.add(cinfo);
                            }
                            response.ListGoFlightInfo.add(info);
                        }
                    }
                }
            }
            response.IsSuccess = true;
        } catch (Exception e) {
            response.ErrorCode = EnumHelper.ReturnCode.系统异常代码.toString();
            response.ErrorMsg = e.getMessage();
            return response;
        }
        return response;
    }

    /**
     * 某一航班报价查询（报价搜索接口）
     *
     * @return
     */
    public QnnarFlightSearchPriceResponse _FlightSearchPrice(String OrgAirport,
                                                             String DstAirport, String DepDate, String FlightNo, String BackDate) {
        QnnarFlightSearchPriceResponse response = new QnnarFlightSearchPriceResponse();


        String strRequestData = "";
        String strResponseData = "";
        Date requestTime = new Date();

        try {

            MoQunar mo = new MoQunar("flight.national.supply.sl.searchprice", requestTime.getTime());
            if (!StringUtils.isNotEmpty(BackDate)) {
                //单程
                Map<String, String> applyData = new HashMap<>();
                applyData.put("dpt", OrgAirport);
                applyData.put("arr", DstAirport);
                applyData.put("date", DepDate);
                applyData.put("flightNum", FlightNo);
                applyData.put("ex_track", ex_track);

                strResponseData = _GetResponseData(mo, applyData, strRequestData);
            } else {
                //往返
                Map<String, String> applyData1 = new HashMap<>();
                applyData1.put("depCity", OrgAirport);
                applyData1.put("arrCity", DstAirport);
                applyData1.put("goDate", DepDate);
                applyData1.put("backDate", BackDate);
                applyData1.put("flightCodes", FlightNo);
                applyData1.put("exTrack", ex_trackRound);

                mo = new MoQunar("flight.national.supply.round.searchprice", requestTime.getTime());

                strResponseData = _GetResponseData(mo, applyData1, strRequestData);
            }
            if (!StringUtils.isNotEmpty(strResponseData)) {
                response.code = EnumHelper.ReturnCode.接口返回参数为空.getValue();
                response.message = "未查询到航班报价信息";
                return response;
            }
            response = JSON.parseObject(strResponseData, QnnarFlightSearchPriceResponse.class);

        } catch (Exception e) {
            response.code = EnumHelper.ReturnCode.系统异常代码.getValue();
            response.message = e.getMessage();
            return response;
        }

        return response;
    }


    /**
     * 查询退改签说明
     *
     * @param moRequest 请求对象
     * @return
     */
    @Override
    public MoCabinTgqResponse _GetCabinTgq(MoCabinTgqRequest moRequest) {

        MoCabinTgqResponse response = new MoCabinTgqResponse();

        Date requestTime = new Date();


        try {
            //从数据库获取缓存退改签
            if (!Strings.isNullOrEmpty(moRequest.PolicyId)) {

            }
            //调用接口获取退改签
            /*else {*/
            //发起航班报价查询
            QnnarFlightSearchPriceResponse flightSearchPrice = this._FlightSearchPrice(moRequest.OrgAirport, moRequest.DstAirport,
                    moRequest.DepDate, moRequest.FlightNo, moRequest.BackDate);

            if (!Strings.isNullOrEmpty(moRequest.BackDate)) {
                flightSearchPrice.result.vendors = flightSearchPrice.result.packVendors;
            }

            if (flightSearchPrice.code == 0 && flightSearchPrice.result != null
                    && flightSearchPrice.result.vendors != null) {

                CabinInfoVendor cinfo = null;
                String errmsg = "";

                for (CabinInfoVendor vendor : flightSearchPrice.result.vendors) {
                    if (vendor.cabin.equals(moRequest.Cabin)) {
                        if (vendor.barePrice.equals(moRequest.Price)) {
                            cinfo = vendor;
                            break;
                        } else {
                            errmsg = "舱位价格已变动，请重新查询航班";
                        }
                    }
                }

                if (cinfo == null) {
                    response.ErrorCode = EnumHelper.ReturnCode.失败.toString();
                    response.ErrorMsg = Strings.isNullOrEmpty(errmsg) || errmsg.trim().length() != 0 ? "舱位已售完，请重新查询预订" : errmsg;
                    response.IsSuccess = false;
                    return response;
                }

                //往返程接口
                if (!Strings.isNullOrEmpty(moRequest.BackDate)) {

                    List<String[]> list = new ArrayList<>();

                    //创建线程池
                    ThreadPoolExecutor executor = new ThreadPoolExecutor(10,
                            10,
                            60L,
                            TimeUnit.SECONDS,
                            new ArrayBlockingQueue<Runnable>(1),
                            Executors.defaultThreadFactory(), (r, executors) -> {
                        System.out.println("无法处理的任务：" + r.toString());
                    }) {
                        @Override
                        protected void beforeExecute(Thread t, Runnable r) {
                            System.out.println(System.currentTimeMillis() + "," + t.getName() + ",开始执行任务:" + r.toString());
                        }

                        @Override
                        protected void afterExecute(Runnable r, Throwable t) {

                            System.out.println(System.currentTimeMillis() + "," + Thread.currentThread().getName() + ",任务:" + r.toString() + "，执行完毕!");
                        }

                        @Override
                        protected void terminated() {
                            System.out.println(System.currentTimeMillis() + "," + Thread.currentThread().getName() + "，关闭线程池!");
                        }
                    };


                    //发起退改签接口查询
                    CabinInfoVendor finalCinfo = cinfo;
                    Date finalRequestTime1 = requestTime;
                    Thread task1 = new Thread(new Runnable() {
                        @Override
                        public void run() {
                            String[] tt = new String[]{"", "", "退改签"};
                            String requestData = "";
                            MoQunar mo = new MoQunar("flight.national.supply.round.tgqNew", finalRequestTime1.getTime());

                            //应用级参数
                            TgqRoundGQDto roundGQDto = new TgqRoundGQDto();
                            roundGQDto.client = finalCinfo.domain; // 供应商域名
                            roundGQDto.carrier = flightSearchPrice.result.go.carrier;
                            roundGQDto.depCode = moRequest.OrgAirport;
                            roundGQDto.arrCode = moRequest.DstAirport;
                            roundGQDto.goDate = moRequest.DepDate;
                            roundGQDto.backDate = moRequest.BackDate;
                            roundGQDto.outCabin = finalCinfo.outCabin;
                            roundGQDto.retCabin = finalCinfo.retCabin;
                            roundGQDto.businessExts = finalCinfo.businessExts; //报价的业务扩展字段
                            roundGQDto.goFlightNum = flightSearchPrice.result.go.flightCode;
                            roundGQDto.backFlightNum = flightSearchPrice.result.back.flightCode;
                            roundGQDto.policyId = Long.valueOf(finalCinfo.policyId);
                            //roundGQDto.price = finalCinfo.price;
                            roundGQDto.barePrice = String.valueOf(finalCinfo.barePrice);
                            roundGQDto.tagName = finalCinfo.tagName;

                            try {
                                tt[1] = _GetResponseData(mo, roundGQDto, requestData);
                            } catch (URISyntaxException e) {
                                e.printStackTrace();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                            tt[0] = requestData;

                            System.out.println("往返机票退改签接口查询线程");

                            list.add(tt);

                        }
                    });
                    task1.setName("往返机票退改签线程");


                    //发起行李额接口查询
                    Date finalRequestTime = requestTime;
                    Thread task2 = new Thread(new Runnable() {
                        @Override
                        public void run() {
                            String[] tt = new String[]{"", "", "行李额"};
                            String requestData = "";

                            String goFlightNo = flightSearchPrice.result.go.carrier;
                            if (flightSearchPrice.result.go.codeShare) {
                                goFlightNo = flightSearchPrice.result.go.mainCarrier;
                            }

                            String backFlightNo = flightSearchPrice.result.back.carrier;
                            if (flightSearchPrice.result.back.codeShare) {
                                backFlightNo = flightSearchPrice.result.back.mainCarrier;
                            }

                            MoQunar mo = new MoQunar("flight.national.supply.round.baggagerule", finalRequestTime.getTime());

                            //应用参数

                            //去程
                            BaggageRuleReqParam goRuleReqParam = new BaggageRuleReqParam();
                            goRuleReqParam.airlineCode = goFlightNo.substring(0, 2); // (如果是共享航班，传主飞航司二字码)航司二字码
                            goRuleReqParam.cabin = finalCinfo.outCabin;
                            goRuleReqParam.depCode = moRequest.OrgAirport;
                            goRuleReqParam.arrCode = moRequest.DstAirport;
                            goRuleReqParam.saleDate = moRequest.DepDate; // 起飞日期
                            goRuleReqParam.depDate = moRequest.DepDate;

                            //往返
                            BaggageRuleReqParam backRuleReqParam = new BaggageRuleReqParam();
                            backRuleReqParam.airlineCode = backFlightNo.substring(0, 2); // (如果是共享航班，传主飞航司二字码)航司二字码
                            backRuleReqParam.cabin = finalCinfo.retCabin;
                            backRuleReqParam.arrCode = moRequest.OrgAirport;
                            backRuleReqParam.depCode = moRequest.DstAirport;
                            backRuleReqParam.saleDate = moRequest.BackDate;
                            backRuleReqParam.depDate = moRequest.BackDate;


                            Object[] applyData = new Object[]{goRuleReqParam, backRuleReqParam};

                            try {
                                tt[1] = _GetResponseData(mo, applyData, requestData);
                            } catch (URISyntaxException e) {
                                e.printStackTrace();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                            tt[0] = requestData;

                            list.add(tt);

                            System.out.println("往返机票行李额接口查询线程");
                        }
                    });
                    task2.setName("往返机票行李额线程");

                    //执行多个任务
                    executor.execute(task1);
                    executor.execute(task2);
                    try {
                        Thread.sleep(10);
                        //关闭任务
                        executor.shutdown();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    //整合数据
                    for (int i = 0; i < list.size(); i++) {
                        if (list.get(i) != null) {
                            String[] res = list.get(i);
                            if (res[2] == "退改签") {
                                String tongyong = "以航司为准";
                                if (!Strings.isNullOrEmpty(res[1]) || res[1].trim().length() != 0) {
                                    BackQunarCabinTgqResponse tgq = JSON.parseObject(res[1], BackQunarCabinTgqResponse.class);
                                    if (tgq.code == 0 && tgq.result != null) {
                                        int num = 1;
                                        for (TgqShowData tag : tgq.result) {
                                            if (!Strings.isNullOrEmpty(tag.returnText)) {
                                                String bag = "";
                                                MoCabinRule moCabinRule = new MoCabinRule();
                                                moCabinRule.Refund = tag.returnText;
                                                moCabinRule.LegNum = num;
                                                moCabinRule.Change = tag.changeText;
                                                moCabinRule.Sign = tag.signText;
                                                moCabinRule.PsgType = 1;
                                                response.MoCabinRuleList.add(moCabinRule);
                                                num++;
                                            } else {
                                                MoCabinRule moCabinRule = new MoCabinRule();
                                                moCabinRule.Refund = tongyong;
                                                moCabinRule.LegNum = num;
                                                moCabinRule.Change = tongyong;
                                                moCabinRule.Sign = tongyong;
                                                moCabinRule.PsgType = 1;
                                                response.MoCabinRuleList.add(moCabinRule);
                                            }

                                        }
                                    }
                                }
                            } else if (res[2] == "行李额") {

                                if (!Strings.isNullOrEmpty(res[1]) || res[1].trim().length() != 0) {
                                    BackQunarBaggageRuleResponse baggage = JSON.parseObject(res[1], BackQunarBaggageRuleResponse.class);
                                    if (baggage.code == 0 && baggage.success) {
                                        int num = 1;
                                        for (BackQunarBaggageRuleResult baggageRuleResult : baggage.result) {
                                            if (baggageRuleResult.baggageRuleInfo != null) {
                                                int finalNum = num;
                                                MoCabinRule rl = response.MoCabinRuleList.stream()
                                                        .filter(item -> item.LegNum == finalNum && item.PsgType == 1)
                                                        .findFirst().orElse(null);

                                                for (String desc : baggageRuleResult.baggageRuleInfo.specialRules) {
                                                    rl.Baggage += desc;
                                                }
                                            }
                                            num++;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //单程接口
                else {
                    requestTime = new Date();
                    int count = 2;
                    if (cinfo.prtag == "OPL28") {
                        count = 3;
                    }
                    List<String[]> strList = new ArrayList<>();
                    //创建线程池
                    ThreadPoolExecutor executor = new ThreadPoolExecutor(10,
                            10,
                            60L,
                            TimeUnit.SECONDS,
                            new ArrayBlockingQueue<Runnable>(1),
                            Executors.defaultThreadFactory(), (r, executors) -> {
                        System.out.println("无法处理的任务：" + r.toString());
                    }) {
                        @Override
                        protected void beforeExecute(Thread t, Runnable r) {
                            System.out.println(System.currentTimeMillis() + "," + t.getName() + ",开始执行任务:" + r.toString());
                        }

                        @Override
                        protected void afterExecute(Runnable r, Throwable t) {

                            System.out.println(System.currentTimeMillis() + "," + Thread.currentThread().getName() + ",任务:" + r.toString() + "，执行完毕!");
                        }

                        @Override
                        protected void terminated() {
                            System.out.println(System.currentTimeMillis() + "," + Thread.currentThread().getName() + "，关闭线程池!");
                        }
                    };

                    //发起退改签接口查询
                    Date finalRequestTime2 = requestTime;
                    CabinInfoVendor finalCinfo1 = cinfo;
                    Thread task1 = new Thread(new Runnable() {
                        @Override
                        public void run() {
                            String[] tt = new String[]{"", "", "退改签"};
                            String requestData = "";
                            MoQunar mo = new MoQunar("flight.national.supply.sl.tgqNew", finalRequestTime2.getTime());

                            String[] split = flightSearchPrice.result.date.split("-");
                            StringBuffer buffer = new StringBuffer();
                            for (int i = 0; i < split.length; i++) {
                                buffer.append(split[i]);
                            }

                            //应用级参数

                            TgqSlGQDto tgqSlApplyDataDto = new TgqSlGQDto();
                            tgqSlApplyDataDto.client = finalCinfo1.domain;// 供应商域名
                            tgqSlApplyDataDto.dpt = flightSearchPrice.result.depCode; //出发机场三字码
                            tgqSlApplyDataDto.businessExt = finalCinfo1.businessExt; //报价的业务扩展字段
                            tgqSlApplyDataDto.arr = flightSearchPrice.result.arrCode; //到达机场三字码
                            tgqSlApplyDataDto.dptDate = buffer.toString(); //起飞时间 yyyyMMdd (2021-10-10)
                            tgqSlApplyDataDto.dptTime = flightSearchPrice.result.btime; //时间 HH:mm
                            tgqSlApplyDataDto.cabin = finalCinfo1.cabin; //仓位

                            BigDecimal minSellPrice = new BigDecimal(String.valueOf(finalCinfo1.vppr));
                            tgqSlApplyDataDto.minSellPrice = minSellPrice.floatValue(); // 最小销售价

                            tgqSlApplyDataDto.policyId = Long.valueOf(finalCinfo1.policyId); // 政策id

                            BigDecimal maxSellPrice = new BigDecimal(String.valueOf(finalCinfo1.barePrice));
                            tgqSlApplyDataDto.maxSellPrice = maxSellPrice.floatValue(); // 裸票价


                            BigDecimal printPrice = new BigDecimal(String.valueOf(finalCinfo1.vppr));
                            tgqSlApplyDataDto.printPrice = printPrice.floatValue(); //票面价

                            tgqSlApplyDataDto.flightNum = moRequest.FlightNo;


                            tgqSlApplyDataDto.tagName = finalCinfo1.prtag; //价格类型
                            tgqSlApplyDataDto.sfid = finalCinfo1.groupId; //群组id
                            tgqSlApplyDataDto.translate = false; //是否翻译
                            tgqSlApplyDataDto.needPercentTgqText = false;

                            try {

                                tt[1] = _GetResponseData(mo, tgqSlApplyDataDto, requestData);

                            } catch (URISyntaxException e) {
                                e.printStackTrace();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                            tt[0] = requestData;

                            strList.add(tt);

                            System.out.println("单程机票退改签接口查询线程");
                        }
                    });
                    task1.setName("单程机票退改签线程");

                    //发起行李额接口查询
                    CabinInfoVendor finalCinfo2 = cinfo;
                    Date finalRequestTime3 = requestTime;
                    CabinInfoVendor finalCinfo3 = cinfo;
                    Thread task2 = new Thread(new Runnable() {
                        @Override
                        public void run() {

                            String[] tt = new String[]{"", "", "行李额"};
                            String requestData = "";
                            String cd = flightSearchPrice.result.carrier;
                            if (finalCinfo2.shareShowAct && !Strings.isNullOrEmpty(moRequest.Carrier)) {
                                cd = moRequest.Carrier.substring(0, 2);
                            }
                            MoQunar mo = new MoQunar("flight.national.supply.sl.baggagerule", finalRequestTime3.getTime());
                            //应用级别参数
                            TgqSlXLEDto xleDto = new TgqSlXLEDto();
                            xleDto.airlineCode = cd; //如果是共享航班，传主飞航司二字码)航司二字码
                            xleDto.cabin = finalCinfo3.cabin;
                            xleDto.depCode = flightSearchPrice.result.depCode;
                            xleDto.arrCode = flightSearchPrice.result.arrCode;

                            xleDto.luggage = finalCinfo3.luggage;

                            xleDto.saleDate = flightSearchPrice.result.date; //销售日期
                            xleDto.depDate = flightSearchPrice.result.date; //起飞日期 2017-06-15

                            try {
                                tt[1] = _GetResponseData(mo, xleDto, requestData);
                            } catch (URISyntaxException | IOException e) {
                                e.printStackTrace();
                            }

                            tt[0] = requestData;

                            strList.add(tt);

                            System.out.println("单程机票行李额接口查询线程");
                        }
                    });
                    task2.setName("单程机票行李额线程");

                    // TODO 该产品暂时没有，考虑以后在加
                    if ("OPL28".equals(cinfo.prtag)) {
                        //发起验价接口查询
                        CabinInfoVendor finalCinfo4 = cinfo;
                        Thread task3 = new Thread(new Runnable() {
                            @Override
                            public void run() {
                                String[] tt = new String[]{"", "", "验价"};
                                MoQunar mo = new MoQunar("flight.national.supply.sl.bk", new Date().getTime());
                                String depDate = moRequest.DepDate;
                                String strRequestDataJson = "";
                                // 应用级参数
                                Map<String, Object> applyData = new HashMap<>();
                                applyData.put("ticketPrice", finalCinfo4.vppr.toString()); //票面价
                                applyData.put("barePrice", finalCinfo4.basePrice.toString());//裸票价
                                applyData.put("price", finalCinfo4.price.toString());// booking价,优先传搜索裸票价, 没有裸票价传包装价
                                applyData.put("basePrice", finalCinfo4.basePrice.toString()); //政策价
                                applyData.put("businessExt", finalCinfo4.businessExt); //报价搜索返回的业务扩展字段
                                applyData.put("tag", finalCinfo4.prtag); //产品Tag
                                applyData.put("carrier", moRequest.FlightNo.substring(0, 2)); //航司
                                applyData.put("flightNum", moRequest.FlightNo); //航班号
                                applyData.put("cabin", moRequest.Cabin); //仓位
                                applyData.put("from", moRequest.OrgAirport); //起飞地
                                applyData.put("to", moRequest.DstAirport); //抵达地
                                applyData.put("policyType", finalCinfo4.policyType);//政策类型
                                applyData.put("wrapperId", finalCinfo4.wrapperId); //wrapperId
                                applyData.put("startTime", depDate); //起飞日期 yyyyMMdd
                                applyData.put("client", finalCinfo4.domain);//代理商域名
                                applyData.put("policyId", finalCinfo4.policyId); //政策Id
                                applyData.put("dptTime", depDate); //起飞时间  HHmm
                                applyData.put("flightType", 1);//航程类型 1 标识单程
                                applyData.put("userName", UserName); //去哪儿用户名

                                //发起请求
                                try {
                                    tt[1] = _GetResponseData(mo, applyData, strRequestDataJson);
                                } catch (URISyntaxException e) {
                                    e.printStackTrace();
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                tt[0] = strRequestDataJson;

                                strList.add(tt);

                                System.out.println("单程机票验价接口查询线程");
                            }
                        });
                        task3.setName("单程机票验价线程");

                        executor.execute(task3);
                    }

                    //执行多个任务
                    executor.execute(task1);
                    executor.execute(task2);

                    try {
                        Thread.sleep(10);
                        //关闭任务
                        executor.shutdown();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    //整合数据
                    for (int i = 0; i < strList.size(); i++) {
                        if (strList.get(i) != null) {
                            String[] res = strList.get(i);
                            if (res[2] == "退改签") {
                                if (!Strings.isNullOrEmpty(res[1]) || res[1].trim().length() != 0) {
                                    QunarCabinTgqResponse tgq = JSON.parseObject(res[1].replace("可咨询客服电话（95117）", ""), QunarCabinTgqResponse.class);
                                    if (tgq.code == 0 && tgq.result != null) {
                                        if (tgq.result.returnText != null && !Strings.isNullOrEmpty(tgq.result.returnText)) {
                                            response.Ttext = tgq.result.returnText;
                                            if (!Strings.isNullOrEmpty(tgq.result.changeText)) {
                                                response.Gtext = tgq.result.changeText;
                                            } else {
                                                response.Gtext = "以航司为准";
                                            }

                                            if (!Strings.isNullOrEmpty(tgq.result.signText)) {
                                                response.Qtext = tgq.result.signText;
                                            } else {
                                                response.Qtext = "以航司为准";
                                            }
                                            response.ChildTgqText = tgq.result.childTgqText;
                                        } else if (tgq.result.tgqPercentText != null) {
                                            response.Ttext = tgq.result.tgqPercentText;
                                        } else {
                                            response.Ttext = "以航司为准.";
                                            response.Gtext = "以航司为准";
                                            response.Qtext = "以航司为准";
                                        }
                                    }
                                }
                            } else if (res[2] == "行李额") {
                                if (!Strings.isNullOrEmpty(res[1]) || res[1].trim().length() != 0) {
                                    QunarBaggageRuleResponse baggage = JSON.parseObject(res[1], QunarBaggageRuleResponse.class);
                                    if (baggage.code == 0 && baggage.result != null) {
                                        response.Baggages = baggage.result.specialRules;
                                    }
                                }

                            } else if (res[2] == "验价") {
                                if (!Strings.isNullOrEmpty(res[1]) || res[1].trim().length() != 0) {
                                    QunarFlightCheckResponse baggage = JSON.parseObject(res[1], QunarFlightCheckResponse.class);
                                    if (baggage.code == 0 && baggage.result != null && baggage.result.specialProductRule != null && baggage.result.specialProductRule.ageScope != null) {
                                        response.ageScope = baggage.result.specialProductRule.ageScope.replace(",", "-").replace("|", ",");
                                        response.passengerNum = baggage.result.specialProductRule.passengerNum;
                                        response.cardType = baggage.result.specialProductRule.cardType;
                                    }
                                }
                            }

                        }
                    }

                }
                if (response.MoCabinRuleList.size() > 0 || !Strings.isNullOrEmpty(response.Ttext)) {
                    response.IsSuccess = true;
                }
            } else {
                response.ErrorCode = EnumHelper.ReturnCode.失败.toString();
                response.ErrorMsg = flightSearchPrice.message;
                response.IsSuccess = false;
            }

            /*}*/

        } catch (Exception e) {
            response.ErrorCode = EnumHelper.ReturnCode.系统异常代码.toString();
            response.ErrorMsg = e.getMessage();
            return response;
        }

        return response;
    }


    /**
     * 舱位验价
     *
     * @param moRequest
     * @return
     */
    @Override
    public MoFlightCheckResponse _FlightCheck(MoFlightCheckRequest moRequest) {

        MoFlightCheckResponse response = new MoFlightCheckResponse();

        String strResponseData = "";
        Date requestTime;
        try {
            //发起航班报价查询
            QnnarFlightSearchPriceResponse finfoResponse = this._FlightSearchPrice(moRequest.OrgAirport, moRequest.DstAirport,
                    moRequest.DepDate, moRequest.FlightNo, moRequest.BackDate);

            if (!Strings.isNullOrEmpty(moRequest.BackDate)) {
                finfoResponse.result.vendors = finfoResponse.result.packVendors;
            }

            if (finfoResponse.code == 0 && finfoResponse.result != null) {
                String depDate = moRequest.DepDate;
                //获取仓位位置
                if (finfoResponse.result.vendors != null) {

                    CabinInfoVendor cinfo = null;
                    String errmsg = "";

                    for (CabinInfoVendor item : finfoResponse.result.vendors) {
                        if (item.cabin.equals(moRequest.Cabin)) {
                            if (item.barePrice.equals(moRequest.Price)) {
                                cinfo = item;
                                break;
                            } else {
                                errmsg = "舱位价格已变动，请重新查询航班";
                            }
                        }
                    }

                    if (cinfo == null) {
                        response.ErrorCode = EnumHelper.ReturnCode.舱位已售完请重新查询.toString();
                        response.ErrorMsg = Strings.isNullOrEmpty(errmsg) ? "舱位已售完，请重新查询预订" : errmsg;
                        response.IsSuccess = false;
                        return response;
                    }

                    //0表示经济舱，1表示头等舱，2表示商务舱，3表示经济舱精选，4表示经济舱y舱，5表示超值头等舱。-1表示未配置
                    if (cinfo.cabinType == 0 || cinfo.cabinType == 3 || cinfo.cabinType == 4) {
                        response.cabinLevel = 3; //(int) EnumHelper.CabinLevel.经济舱;
                    } else if (cinfo.cabinType == 1 || cinfo.cabinType == 5) {
                        response.cabinLevel = 1; //(int)EnumHelper.CabinLevel.头等舱;
                    } else if (cinfo.cabinType == 2) {
                        response.cabinLevel = 2; //(int)EnumHelper.CabinLevel.公务舱;
                    } else {
                        response.cabinLevel = 30; // (int)EnumHelper.CabinLevel.特惠优选;
                    }

                    //发起验价
                    String strRequestData = "";
                    requestTime = new Date();
                    MoQunar mo = new MoQunar("flight.national.supply.sl.bk", requestTime.getTime());

                    //往返验价
                    if (!Strings.isNullOrEmpty(moRequest.BackDate)) {
                        mo = new MoQunar("flight.national.supply.round.bk", requestTime.getTime());
                        Map<String, Object> applyData1 = new HashMap<>();
                        applyData1.put("bookingParamKey", cinfo.bookingParamKey);
                        strResponseData = _GetResponseData(mo, applyData1, strRequestData);
                    }
                    //单程验价
                    else {

                        //应用级参数
                        Map<String, Object> applyData = new HashMap<>();
                        applyData.put("ticketPrice", cinfo.vppr.toString()); //票面价
                        applyData.put("barePrice", cinfo.barePrice.toString()); //裸票价
                        applyData.put("price", cinfo.price.toString()); //booking价,优先传搜索裸票价, 没有裸票价传包装价
                        applyData.put("basePrice", cinfo.basePrice.toString()); //政策价
                        applyData.put("businessExt", cinfo.businessExt); //报价搜索返回的业务扩展字段
                        applyData.put("tag", cinfo.prtag); //产品Tag
                        applyData.put("carrier", moRequest.Airline); //航司
                        applyData.put("flightNum", moRequest.FlightNo); //航班号
                        applyData.put("cabin", moRequest.Cabin); //仓位
                        applyData.put("from", moRequest.OrgAirport); //起飞地
                        applyData.put("to", moRequest.DstAirport); //抵达地
                        applyData.put("policyType", cinfo.policyType); //政策类型
                        applyData.put("wrapperId", cinfo.wrapperId); //wrapperId

                        //起飞日期转换
                        String[] split = depDate.split("-");
                        String startTime = splitConvertString(split);
                        applyData.put("startTime", startTime); // 起飞日期 yyyyMMdd

                        applyData.put("client", cinfo.domain); //代理商域名
                        applyData.put("policyId", cinfo.policyId); //政策Id

                        //起飞时间转换
                        String[] btime = finfoResponse.result.btime.split(":");
                        String dptTime = splitConvertString(btime);
                        applyData.put("dptTime", dptTime); //起飞时间 HHmm

                        applyData.put("flightType", "1"); //航程类型 1 标识单程
                        applyData.put("userName", UserName); // 去哪儿用户名

                        //发起请求
                        strResponseData = _GetResponseData(mo, applyData, strRequestData);

                    }

                    if (Strings.isNullOrEmpty(strResponseData)) {
                        response.ErrorCode = EnumHelper.ReturnCode.请求接口异常.toString();
                        response.ErrorMsg = "请求去哪儿BK验价，未返回验价数据";
                        response.IsSuccess = false;
                        return response;
                    }

                    //解析返回数据
                    QunarFlightCheckResponse qsResponse = JSON.parseObject(strResponseData, QunarFlightCheckResponse.class);
                    if (qsResponse.code == 0 && qsResponse.result != null) {
                        if (qsResponse.success.equals("True") && qsResponse.result.tripInfos != null) {
                            Seatnumber seatNumber = qsResponse.result.tripInfos.get(0).clientBookingResult[0].cabinInfo.seatNumber;
                            Pricetag priceTag = qsResponse.result.tripInfos.get(0).clientBookingResult[0].priceInfo.priceTag;
                            if (seatNumber == null || priceTag == null) {
                                response.ErrorCode = EnumHelper.ReturnCode.解析返回信息异常.toString();
                                response.ErrorMsg = "解析返回信息异常：未找到座位库存信息或价格信息！";
                                response.IsSuccess = false;
                                return response;
                            }
                            // 解析舱位数量
                            if (seatNumber.adultCabinNumber.equals("A")) {
                                response.SeatCount = 10;
                            } else {
                                int cn = Integer.parseInt(seatNumber.adultCabinNumber);
                                response.SeatCount = cn;
                                if (response.SeatCount == 0) {
                                    response.ErrorCode = EnumHelper.ReturnCode.舱位已售完请重新查询.toString();
                                    response.ErrorMsg = "舱位已售完，请重新查询预订";
                                    response.IsSuccess = false;
                                    return response;
                                }
                            }
                            // 获取价格
                            String[] strTags = {"ADU", "CHI", "INF"};


                            response.TicketAmount = priceTag.ADU[0].barePrice;    // 成人
                            //response.cabinName = qsResponse.result.flightInfo[0].cbcn;

                            response.ChildTicketAmount = priceTag.CHI[0].barePrice;   // 儿童

                            // 基建燃油

                            response.AirportTax = qsResponse.result.tripInfos.get(0).clientBookingResult[0].priceInfo.constructionFee;

                            response.FuelTax = qsResponse.result.tripInfos.get(0).clientBookingResult[0].priceInfo.fuelTax;

                            response.ChildFuelTax = qsResponse.result.tripInfos.get(0).clientBookingResult[0].priceInfo.childFuelTax;

                        } else if (qsResponse.result.bookingStatus.equals("BOOKING_SUCCESS") && qsResponse.result.priceInfo != null) {
                            // 报价信息
                            Inventory inventory = qsResponse.result.priceInfo.inventory;
                            Map<String, List<PriceTagInfo>> priceTag = qsResponse.result.priceInfo.priceTag;
                            if (inventory == null || priceTag == null || (priceTag != null && priceTag.size() == 0)) {
                                response.ErrorCode = EnumHelper.ReturnCode.解析返回信息异常.toString();
                                response.ErrorMsg = "解析返回信息异常：未找到座位库存信息或价格信息！";
                                response.IsSuccess = false;
                                return response;
                            }
                            // 解析舱位数量
                            if (inventory.adult.equals("A")) {
                                response.SeatCount = 10;
                            } else {
                                int cn = Integer.parseInt(inventory.adult);
                                response.SeatCount = cn;
                                if (response.SeatCount == 0) {
                                    response.ErrorCode = EnumHelper.ReturnCode.舱位已售完请重新查询.toString();
                                    response.ErrorMsg = "舱位已售完，请重新查询预订";
                                    response.IsSuccess = false;
                                    return response;
                                }
                                // 获取价格
                                String[] strTags = {"ADU", "CHI", "INF"};
                                if(priceTag.size()>0){
                                    Iterator<String> it = priceTag.keySet().iterator();
                                    while (it.hasNext()) {
                                        String key = it.next();
                                        List<PriceTagInfo> priceTagInfos = priceTag.get(key);

                                        if (Objects.equals(key, strTags[0])) {
                                            response.TicketAmount = priceTagInfos.get(0).barePrice;    // 成人

                                        } else if (Objects.equals(key, strTags[1])) { //儿童
                                            response.ChildTicketAmount=priceTagInfos.get(0).barePrice;
                                        } else if (Objects.equals(key, strTags[2])) {
                                           //婴儿
                                        }
                                    }
                                }
                                // 基建燃油
                                int airPortTax=Integer.parseInt(qsResponse.result.priceInfo.arf);
                                if(airPortTax>0){
                                    response.AirportTax =new BigDecimal(airPortTax) ;
                                }


                                int tof=Integer.parseInt(qsResponse.result.priceInfo.tof);
                                if(tof>0){
                                    response.FuelTax =new BigDecimal(tof);
                                }


                                int childTof =Integer.parseInt(qsResponse.result.priceInfo.childtof);
                                if(childTof>0){
                                    response.ChildFuelTax =new BigDecimal(childTof);
                                }
                            }
                        }else{
                            response.ErrorCode =EnumHelper.ReturnCode.失败.toString();
                            response.ErrorMsg = _ConvertBookingStatusMsg(qsResponse.result.bookingStatus);
                            response.IsSuccess = false;
                        }
                    }else{
                        response.ErrorCode = EnumHelper.ReturnCode.失败.toString();
                        response.ErrorMsg = Strings.isNullOrEmpty(qsResponse.message) ? "舱位已售完，请重新查询预订" : qsResponse.message;
                        response.IsSuccess = false;
                    }


                } else {
                    response.ErrorCode = EnumHelper.ReturnCode.失败.toString();
                    response.ErrorMsg = finfoResponse.message;
                    response.IsSuccess = false;
                }
            }

        } catch (Exception e) {
            response.ErrorCode = EnumHelper.ReturnCode.系统异常代码.toString();
            response.ErrorMsg = e.getMessage();
            return response;
        }
        return response;
    }

    /**
     * 验价（BK接口）
     *
     * @param moRequest
     * @return
     */
    public QunarFlightCheckResponse FlightCheck(MoFlightCheckRequest moRequest) {


        QunarFlightCheckResponse quanrResponse = new QunarFlightCheckResponse();

        String strResponseData = "";
        Date requestTime;

        try {
            //发起航班报价查询
            QnnarFlightSearchPriceResponse finfoResponse = this._FlightSearchPrice(moRequest.OrgAirport, moRequest.DstAirport,
                    moRequest.DepDate, moRequest.FlightNo, moRequest.BackDate);

            if (!Strings.isNullOrEmpty(moRequest.BackDate)) {
                finfoResponse.result.vendors = finfoResponse.result.packVendors;
            }

            if (finfoResponse.code == 0 && finfoResponse.result != null) {
                String depDate = moRequest.DepDate;
                //获取仓位位置
                if (finfoResponse.result.vendors != null) {

                    CabinInfoVendor cinfo = null;
                    String errmsg = "";

                    for (CabinInfoVendor item : finfoResponse.result.vendors) {
                        if (item.cabin.equals(moRequest.Cabin)) {
                            if (item.barePrice.equals(moRequest.Price)) {
                                cinfo = item;
                                break;
                            } else {
                                errmsg = "舱位价格已变动，请重新查询航班";
                            }
                        }
                    }

                    if (cinfo == null) {

                        quanrResponse.message = Strings.isNullOrEmpty(errmsg) ? "舱位已售完，请重新查询预订" : errmsg;

                        return quanrResponse;
                    }


                    //发起验价
                    String strRequestData = "";
                    requestTime = new Date();
                    MoQunar mo = new MoQunar("flight.national.supply.sl.bk", requestTime.getTime());

                    //往返验价
                    if (!Strings.isNullOrEmpty(moRequest.BackDate)) {
                        mo = new MoQunar("flight.national.supply.round.bk", requestTime.getTime());
                        Map<String, Object> applyData1 = new HashMap<>();
                        applyData1.put("bookingParamKey", cinfo.bookingParamKey);
                        strResponseData = _GetResponseData(mo, applyData1, strRequestData);
                    }
                    //单程验价
                    else {

                        //应用级参数
                        Map<String, Object> applyData = new HashMap<>();
                        applyData.put("ticketPrice", cinfo.vppr.toString()); //票面价
                        applyData.put("barePrice", cinfo.barePrice.toString()); //裸票价
                        applyData.put("price", cinfo.price.toString()); //booking价,优先传搜索裸票价, 没有裸票价传包装价
                        applyData.put("basePrice", cinfo.basePrice.toString()); //政策价
                        applyData.put("businessExt", cinfo.businessExt); //报价搜索返回的业务扩展字段
                        applyData.put("tag", cinfo.prtag); //产品Tag
                        applyData.put("carrier", moRequest.Airline); //航司
                        applyData.put("flightNum", moRequest.FlightNo); //航班号
                        applyData.put("cabin", moRequest.Cabin); //仓位
                        applyData.put("from", moRequest.OrgAirport); //起飞地
                        applyData.put("to", moRequest.DstAirport); //抵达地
                        applyData.put("policyType", cinfo.policyType); //政策类型
                        applyData.put("wrapperId", cinfo.wrapperId); //wrapperId

                        //起飞日期转换
                        String[] split = depDate.split("-");
                        String startTime = splitConvertString(split);
                        applyData.put("startTime", startTime); // 起飞日期 yyyyMMdd

                        applyData.put("client", cinfo.domain); //代理商域名
                        applyData.put("policyId", cinfo.policyId); //政策Id

                        //起飞时间转换
                        String[] btime = finfoResponse.result.btime.split(":");
                        String dptTime = splitConvertString(btime);
                        applyData.put("dptTime", dptTime); //起飞时间 HHmm

                        applyData.put("flightType", "1"); //航程类型 1 标识单程
                        applyData.put("userName", UserName); // 去哪儿用户名

                        //发起请求
                        strResponseData = _GetResponseData(mo, applyData, strRequestData);

                    }

                    if (Strings.isNullOrEmpty(strResponseData)) {
                        quanrResponse.message = "请求去哪儿BK验价，未返回验价数据";
                        return quanrResponse;
                    }

                    //解析返回数据
                    quanrResponse = JSON.parseObject(strResponseData, QunarFlightCheckResponse.class);

                } else {

                    quanrResponse.message = finfoResponse.message;

                }
            }

        } catch (Exception e) {
            e.printStackTrace();
            quanrResponse.message = e.getMessage();
            return quanrResponse;
        }
        return quanrResponse;
    }

    /**
     * 创建订单（创建合作商订单）
     *
     * @param moRequest
     * @return
     */
    @Override
    public MoCreateOrderResponse _OrderCreate(MoCreateOrderRequest moRequest) {

        MoCreateOrderResponse response = new MoCreateOrderResponse();


        String strRequestData = "";
        String strResponseData = "";
        Date requestTime = new Date();

        try {
            //联系手机号用公司的默认手机号，不可将用户的手机号传递给第三方
            if (moRequest.ListGoSegment == null ||
                    (moRequest.ListGoSegment != null && moRequest.ListGoSegment.size() == 0)) {
                response.ErrorCode = EnumHelper.ReturnCode.请求参数解析错误.toString();
                response.ErrorMsg = "未找到行程信息";
                return response;
            }

            //获取验价数据

            MoFlightCheckRequest moFlightCheckRequest = null;
            if(moRequest.TripType==EnumHelper.TripType.单程.getValue()){//单程验价数据
                moFlightCheckRequest = new MoFlightCheckRequest();
                moFlightCheckRequest.FlightNo = moRequest.ListGoSegment.get(0).FlightNo;
                Date depDate = moRequest.ListGoSegment.get(0).DepDate;
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String format1 = format.format(depDate);
                moFlightCheckRequest.DepDate = format1.substring(0,10);
                moFlightCheckRequest.Cabin = moRequest.ListGoSegment.get(0).Cabin;
                moFlightCheckRequest.OrgAirport = moRequest.ListGoSegment.get(0).OrgAirport;
                moFlightCheckRequest.DstAirport = moRequest.ListGoSegment.get(0).DstAirport;
                moFlightCheckRequest.Airline = moRequest.ListGoSegment.get(0).Airline;
                moFlightCheckRequest.PolicyID = "0";
                moFlightCheckRequest.ProductType = "0";
                moFlightCheckRequest.Price = moRequest.ListGoSegment.get(0).Price;
                moFlightCheckRequest.TripType =String.valueOf(EnumHelper.TripType.单程.getValue());
            }else{
                moFlightCheckRequest = new MoFlightCheckRequest();
                String goFlightNo = moRequest.ListGoSegment.get(0).FlightNo;
                String backFlightNo = moRequest.ListBackSegment.get(0).FlightNo;
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date depDate = moRequest.ListGoSegment.get(0).DepDate;
                Date backDate = moRequest.ListBackSegment.get(0).DepDate;
                String goDate = format.format(depDate);
                String back = format.format(backDate);
                String cabin = moRequest.ListGoSegment.get(0).Cabin + "_" + moRequest.ListBackSegment.get(0).Cabin;

                moFlightCheckRequest.FlightNo = goFlightNo+"_"+backFlightNo;
                moFlightCheckRequest.DepDate = goDate.substring(0,10);
                moFlightCheckRequest.Cabin = cabin;
                moFlightCheckRequest.OrgAirport =moRequest.ListGoSegment.get(0).OrgAirport;
                moFlightCheckRequest.DstAirport = moRequest.ListGoSegment.get(0).DstAirport;
                moFlightCheckRequest.Airline = moRequest.ListGoSegment.get(0).Airline;
                moFlightCheckRequest.PolicyID = "0";
                moFlightCheckRequest.ProductType = "0";
                moFlightCheckRequest.Price =moRequest.ListGoSegment.get(0).Price.add(moRequest.ListBackSegment.get(0).Price);
                moFlightCheckRequest.TripType = String.valueOf(EnumHelper.TripType.往返.getValue());
                moFlightCheckRequest.BackDate=back.substring(0,10);
            }

            QunarFlightCheckResponse qsResponse = this.FlightCheck(moFlightCheckRequest);


            if (qsResponse == null) {
                response.ErrorCode = EnumHelper.ReturnCode.失败.toString();
                response.ErrorMsg = "获取验价数据失败";
                response.IsSuccess = false;
                return response;
            }

            if (qsResponse.code == 1) {
                response.ErrorCode = EnumHelper.ReturnCode.失败.toString();
                response.ErrorMsg = qsResponse.message;
                response.IsSuccess = false;
                return response;
            } else {
                MoQunar mo = new MoQunar("flight.national.supply.sl.order", requestTime.getTime());
                String clientSite = "";
                //往返
                if (moRequest.TripType == EnumHelper.TripType.往返.getValue()) {

                    mo = new MoQunar("flight.national.supply.round.order", requestTime.getTime());
                    //应用级参数
                    if (Strings.isNullOrEmpty(moRequest.Contacts.ContactPreNum)) {
                        moRequest.Contacts.ContactPreNum = "86";
                    }

                    List<Object> passengerInfos = new ArrayList<>();
                    List<String> priceTags = new ArrayList<>();
                    for (MoPassenger ps : moRequest.ListMoPassenger) {
                        // 乘客类型
                        int agetype = 0;
                        List<String> tag = new ArrayList<>();
                        //成人
                        if (ps.PassengerType == 1) {
                            agetype = 0;
                            for (ADU adu : qsResponse.result.tripInfos.get(0).clientBookingResult[0].priceInfo.priceTag.ADU) {
                                tag.add(adu.productPackageCode);
                            }
                        }
                        //儿童
                        else if (ps.PassengerType == 2) {
                            agetype = 1;
                            for (CHI chi : qsResponse.result.tripInfos.get(0).clientBookingResult[0].priceInfo.priceTag.CHI) {
                                tag.add(chi.productPackageCode);
                            }
                        }
                        //婴儿
                        else if (ps.PassengerType == 3) {
                            for (INF inf : qsResponse.result.tripInfos.get(0).clientBookingResult[0].priceInfo.priceTag.INF) {
                                tag.add(inf.productPackageCode);
                            }
                        }

                        priceTags.addAll(tag);

                        //证件类型
                        String cardType = "ID";
                        if (ps.IDType == 1) { //身份证
                            cardType = "NI";
                        } else if (ps.IDType == 4) { //护照
                            cardType = "PP";
                        }

                        //乘客信息
                        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                        String birthday = format.format(ps.Birthday);

                        RoundPassengerDto passenger = new RoundPassengerDto();
                        passenger.name = ps.PassengerName;
                        passenger.ageType = agetype;
                        passenger.cardType = cardType;
                        passenger.cardNo = ps.IDNO;
                        passenger.sex = 1;
                        passenger.birthday = birthday;
                        passenger.mobilePreNum = "86";
                        passenger.mobile = ps.PassengerMobile;
                        passenger.priceTags = tag;

                        passengerInfos.add(passenger);

                    }

                    //联系人信息
                    QunarContactDto contact = new QunarContactDto();
                    contact.name = BookingContactInfo.ContactName;
                    contact.mobilePreNum = BookingContactInfo.MobilePhone;
                    contact.mobile = BookingContactInfo.MobilePhone;

                    //报销凭证
                    ReimbursementDto reimbursement = new ReimbursementDto();
                    reimbursement.xcd = moRequest.IsNeedPost;

                    //预定信息
                    BookingInfoDto bookingInfo = new BookingInfoDto();
                    bookingInfo.flightType = qsResponse.result.type;
                    bookingInfo.orderFrom = "DOMESTIC_ROUND_WAY_PACKAGE";
                    bookingInfo.bookingTag = qsResponse.result.bookingTag;
                    bookingInfo.soloChild = qsResponse.result.tripInfos.get(0).clientBookingResult[0].policyInfo.soloChild == true ? 1 : 0;


                    //应用级参数
                    RoundApplyDataDto roundApplyData = new RoundApplyDataDto();
                    roundApplyData.bookingInfo = bookingInfo;
                    roundApplyData.passengerInfos = passengerInfos;
                    roundApplyData.contact = contact;
                    roundApplyData.reimbursement = reimbursement;


                    // 发起请求
                    strResponseData = _GetResponseData(mo, roundApplyData, strRequestData);

                    if (Strings.isNullOrEmpty(strResponseData)) {
                        response.ErrorCode = EnumHelper.ReturnCode.请求接口异常.toString();
                        response.ErrorMsg = "请求去哪儿生单，未返回数据";
                        response.IsSuccess = false;
                        return response;
                    }

                }
                //单程
                else {

                    //应用级参数
                    // 获取价格
                    String[] strTags = {"ADU", "CHI", "INF"};
                    String[] passengerPriceTags = {"", "", ""};
                    Map<String, List<PriceTagInfo>> priceTag = null;
                    if (qsResponse != null) {
                        priceTag = qsResponse.result.priceInfo.priceTag;
                        Iterator<String> it = priceTag.keySet().iterator();
                        List<PriceTagInfo> priceTagInfos = null;
                        while (it.hasNext()) {
                            String key = it.next();
                            priceTagInfos = priceTag.get(key);
                            if (Objects.equals(key, strTags[0])) {
                                passengerPriceTags[0] = priceTagInfos.get(0).tag;
                            } else if (Objects.equals(key, strTags[1])) {
                                passengerPriceTags[1] = priceTagInfos.get(0).tag;
                            } else if (Objects.equals(key, strTags[2])) {
                                passengerPriceTags[2] = priceTagInfos.get(0).tag;
                            }
                        }
                    }

                    List<Object> passengers = new ArrayList<>();

                    for (MoPassenger ps : moRequest.ListMoPassenger) {
                        //乘客类型
                        int agetype = 0;
                        String tag = "";
                        if (ps.PassengerType == 1) {
                            agetype = 0;
                            tag = passengerPriceTags[0];

                        } else if (ps.PassengerType == 2) {
                            agetype = 1;
                            tag = passengerPriceTags[1];

                        } else if (ps.PassengerType == 3) {

                            tag = passengerPriceTags[2];
                        }
                        // 证件
                        String cardType = "ID";
                        if (ps.IDType == 1) {
                            cardType = "NI";
                        } else if (ps.IDType == 4) {
                            cardType = "PP";
                        }

                        //乘客信息
                        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                        String birthday = format.format(ps.Birthday);

                        QunarPassengerDto passenger = new QunarPassengerDto();
                        passenger.name = ps.PassengerName;
                        passenger.ageType = agetype;
                        passenger.cardType = cardType;
                        passenger.cardNo = ps.IDNO;
                        passenger.sex = ps.Sex ? 1 : 0;
                        passenger.birthday = birthday;
                        passenger.passengerPriceTag = tag;
                        passenger.bx = false;
                        passenger.flightDelayBx = false;
                        passenger.tuipiaoBx = false;
                        passenger.mobilePreNum = "86";
                        passenger.phoneNumber = ps.PassengerMobile;

                        passengers.add(passenger);

                    }
                    if (Strings.isNullOrEmpty(moRequest.Contacts.ContactPreNum)) {
                        moRequest.Contacts.ContactPreNum = "86";
                    }

                    MoSegment finfo = null;
                    if (moRequest.ListGoSegment != null) {
                        for (MoSegment moSegment : moRequest.ListGoSegment) {
                            finfo = moSegment;
                        }
                    }


                    String arrTime = "";

                    if (qsResponse != null) {
                        for (FlightCheckinfo flightCheckinfo : qsResponse.result.flightInfo) {
                            if (flightCheckinfo.arrTime != "" || flightCheckinfo.arrTime != null) {
                                arrTime = flightCheckinfo.arrTime;
                            }
                        }
                    }

                    //应用级参数
                    ApplyDataDto applyData = new ApplyDataDto();

                    //Booking 参数
                    applyData.productTag = qsResponse.result.priceInfo.dtTag;
                    applyData.flyFund = false;
                    applyData.isUseBonus = false;
                    applyData.fuelTax = Integer.parseInt(qsResponse.result.flightInfo.get(0).tof);
                    applyData.childFuelTax = Integer.parseInt(qsResponse.result.flightInfo.get(0).ctof);
                    applyData.constructionFee = Integer.parseInt(qsResponse.result.flightInfo.get(0).arf);

                    if(qsResponse.result.extInfo.ticketPirce!=null){
                        applyData.printPrice = new BigDecimal(qsResponse.result.extInfo.ticketPirce);
                    }else{
                        applyData.printPrice = new BigDecimal(0);
                    }

                    if(qsResponse.result.extInfo.ticketPirce!=null){
                        applyData.yPrice = new BigDecimal(qsResponse.result.extInfo.ticketPirce);
                    }else{
                        applyData.yPrice = new BigDecimal(0);
                    }

                    if(qsResponse.result.priceInfo.childTicketPrice!=null){
                        applyData.childPrintPrice = new BigDecimal(qsResponse.result.priceInfo.childTicketPrice);
                    }else{
                        applyData.childPrintPrice = new BigDecimal(0);
                    }

                    applyData.policyType = Integer.parseInt(qsResponse.result.extInfo.policyType);
                    applyData.policyId = Long.valueOf(qsResponse.result.extInfo.policyId);

                    applyData.contact = BookingContactInfo.ContactName;
                    applyData.contactPreNum = "86";
                    applyData.contactMob = BookingContactInfo.MobilePhone;
                    applyData.invoiceType = moRequest.IsNeedPost ? 2 : 1;
                    applyData.address = BookingContactInfo.Address;
                    applyData.contactEmail = BookingContactInfo.Email;


                    applyData.xcd = ""; //是否邮寄行程单 1是 ""否
                    applyData.xcdMethod = ""; //xcd_config表中的id
                    applyData.bxInvoice = "";  // 是否有邮寄保险

                    //航班
                    FlightInfoDto flightInfo = new FlightInfoDto();
                    flightInfo.flightNum = finfo.FlightNo;
                    flightInfo.flightType = 1;
                    flightInfo.stopInfo = qsResponse.result.flightInfo.get(0).stops;
                    flightInfo.deptAirportCode = finfo.OrgAirport;
                    flightInfo.arriAirportCode = finfo.DstAirport;
                    flightInfo.deptCity = qsResponse.result.flightInfo.get(0).dptCity;
                    flightInfo.arriCity = qsResponse.result.flightInfo.get(0).arrCity;

                    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                    String deptDate = format.format(finfo.DepDate);
                    flightInfo.deptDate = deptDate; //出发日期

                    SimpleDateFormat formatTime = new SimpleDateFormat("HHmm");
                    String deptTime = formatTime.format(finfo.DepDate);
                    flightInfo.deptTime = deptTime; //出发时间

                    flightInfo.arriTime = arrTime.replace(":", ""); //抵达时间

                    flightInfo.cabin = finfo.Cabin; //仓位
                    flightInfo.childCabin = Strings.isNullOrEmpty(qsResponse.result.flightInfo.get(0).childCabin)
                            ? "Y" : qsResponse.result.flightInfo.get(0).childCabin;


                    applyData.flightInfo = flightInfo;


                    applyData.passengerCount = moRequest.ListMoPassenger.size(); //乘机人数
                    applyData.passengers = passengers; // 乘机人信息
                    applyData.bookingTag = qsResponse.result.bookingTag;  // bookingtag
                    applyData.qt = qsResponse.result.extInfo.qt; //主站跳转唯一吗
                    applyData.clientSite = qsResponse.result.extInfo.clientId; //代理商域名


                    clientSite = qsResponse.result.extInfo.clientId;

                    //发起请求
                    strResponseData = _GetResponseData(mo, applyData, strRequestData);

                    if (Strings.isNullOrEmpty(strResponseData)) {
                        response.ErrorCode = EnumHelper.ReturnCode.请求接口异常.toString();
                        response.ErrorMsg = "请求去哪儿生单，未返回数据";
                        response.IsSuccess = false;
                        return response;
                    }
                }

                // 解析数据
                QunarOrderCreateResponse createResponse = JSON.parseObject(strResponseData, QunarOrderCreateResponse.class);
                if (createResponse.code == 0 && createResponse.result != null) {
                    if (createResponse.result.status == 0) {
                        if (moRequest.TripType == 2) {
                            response.MainOrderID = createResponse.result.orders.get(0).orderNo;    // 查询订单时，要传回该值
                            response.ExternalNo = String.valueOf(createResponse.result.id);          // 发起支付时，要传回该值
                            response.Domain = clientSite;                             // 代理商域名，支付时和支付前校验接口要回传
                            response.IsSuccess = true;
                            response.PayAmount = new BigDecimal(createResponse.result.noPayAmount);

                        } else {
                            response.MainOrderID = createResponse.result.orderNo;    // 查询订单时，要传回该值
                            response.ExternalNo = String.valueOf(createResponse.result.id);          // 发起支付时，要传回该值
                            response.Domain = clientSite;                             // 代理商域名，支付时和支付前校验接口要回传
                            response.IsSuccess = true;
                            response.PayAmount = new BigDecimal(createResponse.result.noPayAmount);

                        }
                        //调用查询订单接口获取一些信息
                        MoQueryOrderRequest queryReq = new MoQueryOrderRequest();
                        queryReq.OnlyCode = moRequest.OnlyCode;
                        queryReq.ProviderCode = moRequest.ProviderCode;
                        queryReq.RequestType = moRequest.RequestType;
                        queryReq.OrderID = response.MainOrderID;
                        MoQueryOrderResponse queryRes = _QueryOrderInfo(queryReq);
                        if (queryRes.IsSuccess) {
                            MoOrderDetail od = new MoOrderDetail();
                            od.LastIssueTime = queryRes.IssDateLimit;
                            od.OrderID = response.MainOrderID;
                            response.ListMoOrderDetail.add(od);
                        }
                    } else {
                        response.ErrorCode = EnumHelper.ReturnCode.失败.toString();
                        response.ErrorMsg = String.format("{%s}（{%s}）", createResponse.result.errorDesc, createResponse.result.status);
                        response.IsSuccess = false;
                    }

                }
                // 创建失败
                else {
                    response.ErrorCode = EnumHelper.ReturnCode.失败.toString();
                    response.ErrorMsg = String.format("{%s}（{%s}）", createResponse.message, createResponse.code);
                    response.IsSuccess = false;
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
            response.ErrorCode = EnumHelper.ReturnCode.系统异常代码.toString();
            response.ErrorMsg = e.getMessage();
            response.IsSuccess=false;
            return response;
        }

        return response;
    }

    /**
     * 订单验价
     *
     * @param moRequest
     * @return
     */
    @Override
    public MoOrderCheckResponse _OrderCheck(MoOrderCheckRequest moRequest) {


        MoOrderCheckResponse response = new MoOrderCheckResponse();


        String strRequestData = "";
        String strResponseData = "";
        Date requestTime = new Date();

        try {

            MoQunar mo = new MoQunar("flight.national.supply.sl.payValidate", requestTime.getTime());
            if (!Strings.isNullOrEmpty(moRequest.Domain)) {
                //应用级参数
                Map<String, Object> applyData = new HashMap<>();
                applyData.put("clientSite", moRequest.Domain); //代理商域名
                applyData.put("orderId", moRequest.OrderID); //机票订单id 对应下单后的 result.id
                applyData.put("pmCode", "OUTDAIKOU"); //支付方式  EmHelper.EpmCode.OUTDAIKOU.ToString()
                applyData.put("bankCode", BankCode); //支付银行账号

                //发送请求
                strResponseData = _GetResponseData(mo, applyData, strRequestData);

            }
            //单程
            else {
                //应用级参数
                Map<String, Object> applyData = new HashMap<>();
                applyData.put("orderNo", moRequest.OrderID);
                applyData.put("pmCode", "OUTDAIKOU"); //支付方式
                applyData.put("bankCode", BankCode); //支付银行账号

                //发送请求
                strResponseData = _GetResponseData(mo, applyData, strRequestData);

            }

            if (Strings.isNullOrEmpty(strResponseData)) {
                response.ErrorCode = EnumHelper.ReturnCode.请求接口异常.toString();
                response.ErrorMsg = "校验支付信息，未返回数据";
                response.IsSuccess = false;
                return response;
            }

            QunarOrderPayValidateResponse qsResponse = JSON.parseObject(strResponseData, QunarOrderPayValidateResponse.class);

            if (qsResponse.code != 0) {
                response.ErrorCode = EnumHelper.ReturnCode.失败.toString();
                response.ErrorMsg = "验价不通过,原因:" + qsResponse.message;
                response.IsSuccess = false;
                return response;
            }

            response.IsSuccess = true;

        } catch (Exception e) {
            response.ErrorCode = EnumHelper.ReturnCode.系统异常代码.toString();
            response.ErrorMsg = e.getMessage();
            response.IsSuccess = false;
            return response;
        }

        return response;
    }

    /**
     * 支付订单
     *
     * @param moRequest
     * @return
     */
    @Override
    public MoOrderPayResponse _OrderPay(MoOrderPayRequest moRequest) {


        MoOrderPayResponse response = new MoOrderPayResponse();


        String strRequestData = "";
        String strResponseData = "";
        Date requestTime = new Date();

        try {
            MoQunar mo = new MoQunar("flight.national.supply.sl.pay", requestTime.getTime());
            //如果是改期订单支付
            if (!Strings.isNullOrEmpty(moRequest.ChangeOrderID)) {

                mo = new MoQunar("flight.national.supply.sl.changePay", requestTime.getTime());

                //应用级参数
                Map<String, Object> applyData = new HashMap<>();
                applyData.put("orderNo", moRequest.MainOutOrderID); //订单号
                //改签Id，改签申请接口返回，对应节点result->changeApplyResult->gqId
                applyData.put("gqId", moRequest.ChangeOrderID);
                //乘机人ID，多个ID以逗号分隔
                applyData.put("passengerIds", moRequest.ExternalNo);
                applyData.put("totalAmount", moRequest.PayAmount.toString()); //改签支付金额
                applyData.put("pmCode", "OUTDAIKOU"); //支付方式
                applyData.put("bankCode", BankCode); //银行编号
                applyData.put("paymentMerchantCode", AlipayAccount); //付款账户
                applyData.put("curId", "CNY"); //货币代码 固定传“CNY”
                applyData.put("callbackUrl", CallBack); //支付回调地址
                applyData.put("applyRemarks", "金色世纪改签"); //改签支付备注

                //发送请求
                strResponseData = _GetResponseData(mo, applyData, strRequestData);

            }
            //正常订单
            else {
                // 应用级参数
                Map<String, Object> applyData = new HashMap<>();
                applyData.put("orderNo", moRequest.MainOutOrderID); //机票订单id 对应下单后的 result.id
                applyData.put("pmCode", "OUTDAIKOU"); //支付方式
                applyData.put("bankCode", BankCode); //银行编号
                applyData.put("paymentMerchantCode", AlipayAccount); //付款账户
                applyData.put("curId", "CNY"); //货币代码
                applyData.put("bgRetUrl", CallBack); //支付回调地址

                //发送请求
                strResponseData = _GetResponseData(mo, applyData, strRequestData);

            }


            if (Strings.isNullOrEmpty(strResponseData)) {
                response.ErrorCode = EnumHelper.ReturnCode.请求接口异常.toString();
                response.ErrorMsg = "发起支付，未返回数据";
                response.IsSuccess = false;
                return response;
            }

            QunarOrderPayResponse qsResponse = JSON.parseObject(strResponseData, QunarOrderPayResponse.class);

            if (qsResponse.code != 0 || qsResponse.result.code != 0) {
                response.ErrorCode = "失败"; // ((int)EnumHelper.ReturnCode.失败).ToString();
                String strmsg = "";
                if (qsResponse.result != null && qsResponse.result.results != null && qsResponse.result.results.size() > 0) {
                    strmsg = qsResponse.result.results.get(0).errMsg;
                } else {
                    strmsg = qsResponse.message;
                    response.ErrorMsg = "扣款失败,原因:" + strmsg;
                    response.IsSuccess = false;
                    return response;
                }
            }

            response.IsSuccess = true;
            QunarOrderPayInfo rs = qsResponse.result.results.get(0);
            response.PayInfo.PayAmount = new BigDecimal(rs.payAmount);

            String replace = rs.payId.replace("newttsqnf,", "").replace("newttszzgq,", "");
            response.PayInfo.TradeId = StringUtils.removeEnd(replace, ";");

        } catch (Exception e) {
            response.ErrorCode = EnumHelper.ReturnCode.系统异常代码.toString();
            response.ErrorMsg = e.getMessage();
            response.IsSuccess = false;
            return response;
        }

        if (!Strings.isNullOrEmpty(response.ErrorMsg) &&
                response.ErrorMsg.length() >= 500) {
            response.ErrorMsg = response.ErrorMsg.substring(0, 490);
            response.IsSuccess = false;
        }

        return response;
    }

    /**
     * 查询订单信息
     *
     * @param moRequest
     * @return
     */
    @Override
    public MoQueryOrderResponse _QueryOrderInfo(MoQueryOrderRequest moRequest) {

        MoQueryOrderResponse response = new MoQueryOrderResponse();

        String strRequestData = "";
        String strResponseData = "";
        Date requestTime = new Date();

        try {

            MoQunar mo = new MoQunar("flight.national.tts.order.info.detail.get", requestTime.getTime());

            //应用级参数
            Map<String, Object> applyData = new HashMap<>();
            applyData.put("orderNo", moRequest.OrderID);

            response.OrderID = moRequest.OrderID;
            //发送请求
            strResponseData = _GetResponseData(mo, applyData, strRequestData);

            if (Strings.isNullOrEmpty(strResponseData)) {
                response.ErrorCode = EnumHelper.ReturnCode.请求接口异常.toString();
                response.ErrorMsg = "查询订单，未返回数据";
                response.IsSuccess = false;
                return response;
            }

            //解析数据
            QunarQueryOrderInfoResponse qsResponse = JSON.parseObject(strResponseData, QunarQueryOrderInfoResponse.class);
            if (qsResponse.code == 0 && qsResponse.result != null) {
                if (qsResponse.result.code) {
                    //父订单
                    response.ParentOrderID = qsResponse.result.detail.parentOrderNo;

                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    response.IssDateLimit = dateFormat.parse(qsResponse.result.detail.agentLastTicketTime);
                    // 乘客信息
                    response.PassengerNum = qsResponse.result.passengers.size();
                    for (QunarPassengerInfo item : qsResponse.result.passengers) {
                        QunarPassengertype typeInfo = qsResponse.result.passengerTypes.stream().filter(q -> Objects.equals(q.ageType, item.type))
                                .findFirst().orElse(null);

                        MoPassenger moPassenger = new MoPassenger();
                        moPassenger.PassengerName = item.name;
                        moPassenger.TicketNo = item.ticketNo;
                        moPassenger.IDNO = item.cardNum;
                        moPassenger.PNR = qsResponse.result.detail.pnr;
                        moPassenger.TicketAmount = new BigDecimal(typeInfo.realPrice);
                        moPassenger.AirportTax = new BigDecimal(typeInfo.constructionFee);
                        moPassenger.FuelTax = new BigDecimal(typeInfo.fuelTax);

                        response.ListMoPassenger.add(moPassenger);
                    }

                    int sum = 0;
                    for (QunarPassengertype q : qsResponse.result.passengerTypes) {
                        sum += q.allPrices;
                    }

                    //支付金额
                    response.Amount = new BigDecimal(sum);
                    response.PayAmount = response.Amount;

                    //退改签政策
                    if (qsResponse.result.other != null) {
                        response.RRemark = qsResponse.result.other.tgqMsg;
                        if (!Strings.isNullOrEmpty(response.RRemark)) {
                            response.RRemark = response.RRemark.replace("<br />", ";");
                        }
                    }

                    //暂时追加子订单状态，放到退改签里
                    if (qsResponse.result.detail.childrenOrderInfo != null) {
                        String strChildOrderInfo = qsResponse.result.detail.childrenOrderInfo.toString();
                        response.RRemark += "<br/>子订单状态: " + strChildOrderInfo;

                        for (int i = 1; i < 20; i++) {
                            String strM = String.format("(?<=''children%sOrderNo'':.*'').*(?='',)", i);
                            Pattern p = Pattern.compile(strM);
                            Matcher matcher = p.matcher(strChildOrderInfo);
                            String strVal = matcher.group(); //正则里面的值

                            if (Strings.isNullOrEmpty(strVal)) {
                                break;
                            }

                            String strMStatus = String.format("(?<=''children%sStatus'':.*'').*(?='',)", i);
                            Pattern pattern = Pattern.compile(strMStatus);
                            Matcher match = p.matcher(strChildOrderInfo);
                            String strValStatus = match.group();
                            ChildOrderId cid = new ChildOrderId();
                            cid.OrderId = strVal;
                            cid.Status = strValStatus;

                            response.ListChildOrderId.add(cid);
                        }

                    }


                    // 行程
                    for (QunarFlightinfo f : qsResponse.result.flightInfo) {
                        MoSegment moSegment = new MoSegment();
                        moSegment.Cabin = f.cabin;
                        moSegment.FlightNo = f.flightNum;
                        moSegment.PNR = qsResponse.result.detail.pnr;


                        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH:mm-HH:mm");
                        moSegment.DepDate = format.parse(f.deptTime);

                        response.ListGoSegment.add(moSegment);
                    }

                    // 联系人
                    response.Contacts.ContactName = qsResponse.result.contacterInfo.name;
                    response.Contacts.ContactMobile = qsResponse.result.contacterInfo.mobile;
                    response.Contacts.ContactEmail = qsResponse.result.contacterInfo.email;

                    // 订单状态
                    int status = _CnonvertOrderStatus(qsResponse.result.detail.status);
                    response.OrderStatus = status;
                    response.OrderStatusMsg = qsResponse.result.detail.status;

                    if (qsResponse.result.refundDetail != null && qsResponse.result.refundDetail.size() > 0) {
                        for (QunarRefundDetail dt : qsResponse.result.refundDetail) {
                            response.OrderDesc += " 退款类型：" + dt.refundType + "退款金额：" + dt.Price + "退款路径：" + dt.refundPath
                                    + "退款时间：" + dt.refundTime + "。";
                        }
                    }
                    response.IsSuccess = true;
                } else {
                    response.ErrorCode = EnumHelper.ReturnCode.失败.toString();
                    response.ErrorMsg = qsResponse.result.message;
                    response.IsSuccess = false;
                }

            } else {
                response.IsSuccess = false;
                response.ErrorCode = EnumHelper.ReturnCode.失败.toString();
                response.ErrorMsg = String.format("%s（%s）", qsResponse.message, qsResponse.code);
            }

        } catch (Exception e) {
            response.ErrorCode = EnumHelper.ReturnCode.系统异常代码.toString();
            response.ErrorMsg = e.getMessage();
            response.IsSuccess = false;
            return response;
        }

        return response;
    }


    /**
     * 退废票明细查询
     *
     * @param moRequest
     * @param isSubsidy
     * @return
     */
    @Override
    public MoOrderRefundCaltResponse _OrderRefundCalt(MoOrderRefundCaltRequest moRequest,
                                                      boolean isSubsidy) {


        MoOrderRefundCaltResponse response = new MoOrderRefundCaltResponse();


        String strRequestData = "";
        String strResponseData = "";
        Date requestTime = new Date();

        try {
            MoQunar mo = new MoQunar("flight.national.supply.sl.refundSearch", requestTime.getTime());

            //应用级参数
            Map<String, Object> applyData = new HashMap<>();
            applyData.put("orderNo", moRequest.OutOrderID);

            //发送请求
            strResponseData = _GetResponseData(mo, applyData, strRequestData);

            if (Strings.isNullOrEmpty(strResponseData)) {
                response.ErrorCode = EnumHelper.ReturnCode.请求接口异常.toString();
                response.ErrorMsg = "查询退票信息，未返回数据";
                response.IsSuccess = false;
                return response;
            }

            QunarTgSearchResponse qsResponse = JSON.parseObject(strResponseData, QunarTgSearchResponse.class);
            if (qsResponse.code != 0) {
                response.ErrorCode = EnumHelper.ReturnCode.失败.toString();
                response.ErrorMsg = "查询退票信息失败,原因:" + qsResponse.message;
                return response;
            }

            //TODO :等实际退票再说后续逻辑代码编辑，实体类不确定构造正确。
            for (TS_NationalPssenger pssenger : qsResponse.result) {
                if (pssenger.refundSearchResult == null) {
                    continue;
                }

                /*if (!moRequest.ListMoPassenger.Exists(a => a.TicketNo.Replace("-", "") == item.ticketNum.replace("-", ""))){
                    continue;
                }*/

                MoPassenger p = new MoPassenger();
                p.PsgID = Long.toString(pssenger.id);
                p.TicketNo = pssenger.ticketNum;
                p.Birthday = convertToDate(pssenger.birthday);
                p.IDNO = pssenger.cardNum;
                p.PassengerName = pssenger.name;
                p.PsgID = Long.toString(pssenger.id);

                //是否可退款
                if (pssenger.refundSearchResult.canRefund) {

                    TS_TgqReason tgqReason = pssenger.refundSearchResult.tgqReasons.stream().
                            filter(item -> item.code == 16).findFirst().orElse(null);

                    TS_RefundPassengerPriceInfo passengerPriceInfo = tgqReason.refundPassengerPriceInfoList.stream().
                            filter(item -> Objects.equals(item.basePassengerPriceInfo.passengerName, p.PassengerName)).findFirst().orElse(null);

                    p.RefundFee = new BigDecimal(passengerPriceInfo.refundFeeInfo.refundFee);

                    if (passengerPriceInfo.refundFeeInfo.refundFee <= 0) {
                        p.RefundFee = new BigDecimal(-1);
                    }
                }

                // 是否航变全退
                if (pssenger.refundSearchResult.airChangeAllRefund) {
                }

                if (pssenger.refundSearchResult.noTicket) {
                    // 未出票退款
                    if (pssenger.refundSearchResult.noTicketPassengerPriceInfo != null) {
                        for (TS_RefundPassengerPriceInfo info : pssenger.refundSearchResult.noTicketPassengerPriceInfo) {
                            if (info.basePassengerPriceInfo.passengerId == pssenger.id) {
                                p.TicketAmount = new BigDecimal(info.basePassengerPriceInfo.ticketPrice);
                                p.AirportTax = new BigDecimal(info.basePassengerPriceInfo.constructionFee);
                                p.FuelTax = new BigDecimal(info.basePassengerPriceInfo.fuelTax);

                                p.RefundFee = new BigDecimal(info.refundFeeInfo.refundFee);   // 退票扣费
                                if (info.refundFeeInfo.refundFee <= 0) {
                                    p.RefundFee = new BigDecimal(-1);
                                }
                            }
                        }
                    }

                } else {
                    // 出票，申请退票
                }

                // 上传证明
                if (pssenger.refundSearchResult.needUploadProof) {
                }

                // 退改签原因
                if (pssenger.refundSearchResult.tgqReasons != null) {
                }

                response.ListRefundPassenger.add(p);
            }

            response.IsSuccess = true;

        } catch (Exception e) {
            response.ErrorCode = EnumHelper.ReturnCode.系统异常代码.toString();
            response.ErrorMsg = e.getMessage();
            return response;
        }

        return response;
    }


    /**
     * 申请退票
     *
     * @param moRequest
     * @return
     */
    @Override
    public MoOrderRefundResponse _OrderRefund(MoOrderRefundRequest moRequest) {
        moRequest.OnlyCode = strOnlyCode;

        MoOrderRefundResponse response = new MoOrderRefundResponse();
        response.OnlyCode = moRequest.OnlyCode;
        response.ProviderCode = moRequest.ProviderCode;
        response.RequestType = moRequest.RequestType;

        String strRequestData = "";
        String strResponseData = "";
        Date requestTime = new Date();

        try {
            //获取数据
            MoOrderRefundCaltRequest refundCaltRequest = new MoOrderRefundCaltRequest();
            refundCaltRequest.OutOrderID = moRequest.OrderID;
            refundCaltRequest.ListMoPassenger = moRequest.ListMoPassenger;

            //先从去哪接口得到乘客ID
            MoOrderRefundCaltResponse caltResponse = _OrderRefundCalt(refundCaltRequest, false);

            if (!caltResponse.IsSuccess) {
                response.ErrorMsg = "获取可退票乘客失败";
                return response;
            }

            for (MoPassenger moPassenger : moRequest.ListMoPassenger) {
                if (!caltResponse.ListRefundPassenger.stream().
                        anyMatch(item -> Objects.equals(item.PassengerName, moPassenger.PassengerName))) {
                    response.ErrorMsg = String.format("乘客:%s,不允许退票,请检查客票状态或确认是否已拆单", moPassenger.PassengerName);
                    return response;
                }
            }

            String strGuestIds = "";//乘客id
            for (MoPassenger psg : caltResponse.ListRefundPassenger) {
                if (moRequest.ListMoPassenger.stream().
                        anyMatch(item -> Objects.equals(item.PassengerName, psg.PassengerName))) {
                    strGuestIds += psg.PsgID + ",";
                }
            }

            strGuestIds = strGuestIds.substring(0, strGuestIds.length() - 1);
            MoQunar mo = new MoQunar("flight.national.supply.sl.applyRefund", requestTime.getTime());

            // 应用级参数
            Map<String, Object> applyData = new HashMap<>();

            applyData.put("orderNo", moRequest.OrderID); //订单号
            applyData.put("refundCauseId", String.valueOf(_ConvertRefundType(moRequest.RefundType))); //退票原因ID
            applyData.put("passengerIds", strGuestIds); //乘机人id集合  多个 "," 分割
            applyData.put("refundCause", "我不想飞了"); //退票备注
            applyData.put("callbackUrl", CallBack);

            //发送请求
            strResponseData = _GetResponseData(mo, applyData, strRequestData);


            if (Strings.isNullOrEmpty(strResponseData)) {
                response.ErrorCode = EnumHelper.ReturnCode.请求接口异常.toString();
                response.ErrorMsg = "申请退票，未返回数据";
                response.IsSuccess = false;
                return response;
            }

            QunarTgSearchResponse qsResponse = JSON.parseObject(strResponseData, QunarTgSearchResponse.class);

            if (qsResponse.code != 0) {
                response.ErrorCode = EnumHelper.ReturnCode.失败.toString();
                response.ErrorMsg = "申请退票失败,原因:" + qsResponse.message;
                return response;
            }

            if (qsResponse.result.stream().anyMatch(item -> item.refundApplyResult.success == false)) {
                response.ErrorCode = "失败"; //((int)EnumHelper.ReturnCode.失败).ToString();
                response.ErrorMsg = "申请退票失败,原因:" + qsResponse.result.get(0).refundApplyResult.reason;
                return response;
            }

            // TODO:等实际退票再说后续逻辑代码编辑，实体类不确定构造正确。
            response.IsSuccess = true;
            //退票成功之后调用订单查询接口获取当前退票乘客的子订单号，如果未拆单，则获取的是主单号
            try {

                MoQueryOrderRequest queryReq = new MoQueryOrderRequest();
                queryReq.OnlyCode = moRequest.OnlyCode;
                queryReq.OrderID = moRequest.OrderID;

                MoQueryOrderResponse queryRes = _QueryOrderInfo(queryReq);

                if (queryRes.ListChildOrderId != null && queryRes.ListChildOrderId.size() > 0) {
                    for (ChildOrderId childOrderId : queryRes.ListChildOrderId) {
                        MoQueryOrderRequest orderRequest = new MoQueryOrderRequest();
                        orderRequest.OnlyCode = moRequest.OnlyCode;
                        orderRequest.OrderID = childOrderId.OrderId;
                        MoQueryOrderResponse res = _QueryOrderInfo(orderRequest);
                        if (res.ListMoPassenger.stream().
                                anyMatch(item -> item.PassengerName == moRequest.ListMoPassenger.get(0).PassengerName)) {
                            response.RefundOrderID = childOrderId.OrderId;
                            break;
                        }
                    }
                } else {
                    response.RefundOrderID = queryRes.OrderID;
                }


            } catch (Exception e) {
                logger.error("解析去哪儿子订单报错:{}", e.getMessage());
            }


        } catch (Exception ex) {
            response.ErrorCode = EnumHelper.ReturnCode.系统异常代码.toString();
            response.ErrorMsg = ex.getMessage();
            return response;

        }

        return response;
    }

    /**
     * 改签查询
     *
     * @param moRequest
     * @return
     */
    @Override
    public MoFlightSearchResponse _SearchChangeDateFlightInfo(MoRescheduleSearchRequest moRequest) {

        MoFlightSearchResponse response = new MoFlightSearchResponse();

        try {

            String dptDate = data(moRequest.DepartDate, "yyyy-MM-dd");

            QunarTgSearchResponse qsResponse = _ChangeSearch(moRequest.OrderID, dptDate);

            if (qsResponse.code == 0 && qsResponse.result != null) {
                for (TS_NationalPssenger item : qsResponse.result) {
                    //改签查询结果
                    if (item.changeSearchResult != null) {
                        //如果可以改签
                        if (item.changeSearchResult.canChange && item.changeSearchResult.tgqReasons != null) {
                            for (TS_TgqReason tgq : item.changeSearchResult.tgqReasons) {
                                if (tgq.code != 1) {
                                    continue;
                                }
                                if (tgq.changeFlightSegmentList != null) {
                                    for (TS_FlightAlterSearchResultWithText ts : tgq.changeFlightSegmentList) {
                                        // 是否共享航班
                                        if (ts.share) {
                                            continue;
                                        }
                                        int cabinLeft = 0;
                                        if ("A".equals(ts.cabinStatus)) {
                                            cabinLeft = 10;
                                        } else {
                                            if (ts.cabinStatus != null || ts.cabinStatus != "") {
                                                cabinLeft = 1;
                                                continue;
                                            }
                                        }

                                        MoFlightInfo info = new MoFlightInfo();
                                        info.OrgAirport = ts.dptAirportCode;
                                        info.DstAirport = ts.arrAirportCode;
                                        info.DepTerm = ts.dptTerminal;
                                        info.ArrTerm = ts.arrTerminal;

                                        info.DepDate = convertToDate(ts.startTime);
                                        info.ArrDate = convertToDate(ts.endTime);

                                        // 经停
                                        if (ts.stopFlightInfo != null && ts.stopFlightInfo.stopType == 2
                                                && ts.stopFlightInfo.stopCityInfoList != null
                                                && ts.stopFlightInfo.stopCityInfoList.size() > 0) {
                                            for (TS_StopCityInfo stop : ts.stopFlightInfo.stopCityInfoList) {
                                                FlightStopEntity stopEntity = new FlightStopEntity();
                                                stopEntity.StopCityCode = stop.stopAirportCode;
                                                info.ListFlightStop.add(stopEntity);
                                            }

                                        }

                                        info.FlightNo = ts.flightNo;
                                        info.Airline = ts.carrier;
                                        info.AirportTax = moRequest.Tax;
                                        info.FuelTax = moRequest.OilFee;

                                        MoCabinInfo cinfo = new MoCabinInfo();
                                        cinfo.Cabin = ts.cabinCode;
                                        cinfo.BaseAmount = new BigDecimal(moRequest.Price + ts.upgradeFee);
                                        cinfo.CabinLeft = cabinLeft;

                                        // 改期信息赋值
                                        cinfo.DiffPriceAdt = new BigDecimal(ts.upgradeFee);
                                        info.Reschedule.PID = ts.uniqKey;
                                        cinfo.ChangeFeeAdt = new BigDecimal(ts.gqFee);

                                        info.ListCabinInfo.add(cinfo);
                                        response.ListGoFlightInfo.add(info);
                                    }
                                }
                            }
                        }
                    }
                    // 只看一个乘客的
                    break;
                }
                response.IsSuccess = true;

            } else {
                response.ErrorCode = EnumHelper.ReturnCode.失败.toString();
                response.ErrorMsg = qsResponse.message;
            }

        } catch (Exception e) {
            response.ErrorCode = EnumHelper.ReturnCode.系统异常代码.toString();
            response.ErrorMsg = e.getMessage();
            return response;
        }
        return response;
    }

    /**
     * 申请改签
     *
     * @param moRequest
     * @return
     */
    @Override
    public MoOrderChangeResponse _OrderChange(MoOrderChangeRequest moRequest) {

        MoOrderChangeResponse response = new MoOrderChangeResponse();


        String strRequestData = "";
        String strResponseData = "";
        Date requestTime = new Date();

        try {
            int nChangeType = 1;
            if (moRequest.IsFree) {
                nChangeType = 3;
            }
            String dptDate = data(moRequest.NewChangeAirOriDest.DepDate, "yyyy-MM-dd");

            //此处是再次查询了下接口，可以改成数据库查询模式。
            QunarTgSearchResponse qsResponse = _ChangeSearch(moRequest.OrderId, dptDate);
            if (qsResponse.code == 0 && qsResponse.result != null) {
                List<Long> passangerIds = new ArrayList<>();
                TS_FlightAlterSearchResultWithText tsflight = null;
                for (TS_NationalPssenger ps : qsResponse.result) {
                    if (moRequest.ChangePassenger.stream().
                            anyMatch(item -> Objects.equals(item.Name, ps.name))) {
                        passangerIds.add(ps.id);
                        if (tsflight == null) {
                            boolean isBreak = false;
                            for (TS_TgqReason tgq : ps.changeSearchResult.tgqReasons) {
                                //循环找到相关改期类型的数据
                                if (tgq.code != nChangeType) {
                                    continue;
                                }

                                if (tgq.changeFlightSegmentList != null) {
                                    for (TS_FlightAlterSearchResultWithText fl : tgq.changeFlightSegmentList) {
                                        if (Objects.equals(fl.actFlightNo, moRequest.NewChangeAirOriDest.FlightNo)
                                                && Objects.equals(fl.dptAirportCode, moRequest.NewChangeAirOriDest.DepApt)
                                                && Objects.equals(fl.arrAirportCode, moRequest.NewChangeAirOriDest.ArrApt)
                                                && Objects.equals(fl.cabinCode, moRequest.NewChangeAirOriDest.Cabin)) {
                                            tsflight = fl;
                                            isBreak = true;
                                            break;
                                        }
                                    }
                                }
                                if (isBreak) {
                                    break;
                                }

                            }
                        }
                    }
                }

                if (tsflight == null || passangerIds.size() == 0) {
                    response.ErrorMsg = "未找到相关舱位，请重新查询！";
                    return response;
                }

                // 处理qsResponse 数据
                MoQunar mo = new MoQunar("flight.national.supply.sl.applyChange", requestTime.getTime());
                //应用级参数
                ChangesApplyDataDto applyData = new ChangesApplyDataDto();
                applyData.orderNo = moRequest.OrderId;
                applyData.changeCauseId = String.valueOf(nChangeType);

                //处理乘机人id多个ID以逗号分隔
                StringBuffer buffer = null;
                if (passangerIds.size() > 0 && passangerIds != null) {
                    for (Long passengerId : passangerIds) {

                        if (buffer == null) {
                            buffer = new StringBuffer();
                        } else {
                            buffer.append(",");
                        }
                        buffer.append(passengerId);
                    }
                }

                applyData.passengerIds = buffer.toString();

                applyData.applyRemarks = "改签";
                applyData.uniqKey = tsflight.uniqKey; //key
                applyData.gqFee = tsflight.gqFee; //改期费
                applyData.upgradeFee = tsflight.upgradeFee; //升舱费
                applyData.flightNo = tsflight.actFlightNo;
                applyData.cabinCode = tsflight.cabinCode;
                SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
                String date = format.format(moRequest.NewChangeAirOriDest.DepDate);
                applyData.startDate =date; //yyyy-MM-dd
                applyData.startTime = tsflight.startTime; //HH:mm
                applyData.endTime = tsflight.endTime; //HH:mm
                applyData.callbackUrl = CallBack;

                //发送请求
                strResponseData = _GetResponseData(mo, applyData, strRequestData);
                if (Strings.isNullOrEmpty(strResponseData)) {
                    response.ErrorCode = "请求接口异常"; //((int) EnumHelper.ReturnCode.请求接口异常).ToString();
                    response.ErrorMsg = "改期申请，未返回数据";
                    response.IsSuccess = false;
                    return response;
                }

                QunarTgSearchResponse gqResponse = JSON.parseObject(strResponseData, QunarTgSearchResponse.class);
                //解析返回数据如果返回错误，直接返回
                if (gqResponse.code != 0) {
                    response.ErrorMsg = gqResponse.message;
                    return response;
                }
                if (!gqResponse.result.get(0).changeApplyResult.success) {
                    response.ErrorMsg = gqResponse.result.get(0).changeApplyResult.reason;
                    return response;
                }

                //返回改升后的新订单号
                TS_NationalPssenger pssenger = gqResponse.result.get(0);
                response.ApplicationId = pssenger.changeApplyResult.orderNo;//jlx171018161430530
                response.ExternalNo = pssenger.changeApplyResult.orderId;//212390
                response.ChangeId = pssenger.changeApplyResult.gqId;//5307917


                if (moRequest.ChangePassenger.size() > 0 && moRequest.ChangePassenger != null) {
                    BigDecimal ChangePassengerCount = new BigDecimal(moRequest.ChangePassenger.size());
                    BigDecimal allFee = new BigDecimal(tsflight.allFee);
                    //乘法
                    response.PayAmount = ChangePassengerCount.multiply(allFee);

                    response.IsSuccess = true;
                }


                for (TS_NationalPssenger gq : gqResponse.result) {
                    // 改签乘客
                    // ..
                }

                response.IsSuccess = true;

            } else {
                response.ErrorCode = EnumHelper.ReturnCode.失败.toString();
                response.ErrorMsg = qsResponse.message;
            }

        } catch (Exception e) {
            response.ErrorCode = EnumHelper.ReturnCode.系统异常代码.toString();
            response.ErrorMsg = e.getMessage();
            return response;
        }

        return response;
    }

    /**
     * 取消订单接口
     *
     * @param request
     * @return
     */
    @Override
    public MoCancelOrderResponse _CancelOrder(MoCancelOrderRequest request) {

        MoCancelOrderResponse response = new MoCancelOrderResponse();
        response.RequestType = request.RequestType;
        response.OnlyCode = request.OnlyCode;


        try {
            response.IsSuccess = true;
            return response;
        } catch (Exception e) {
            response.ErrorCode = EnumHelper.ReturnCode.系统异常代码.toString();
            response.ErrorMsg = e.getMessage();
            return response;
        }

    }


    /**
     * 航变通知接口
     *
     * @param moRequest
     * @return
     */
    @Override
    public MoFlightChangeNoticeResponse _FlightChangeNotice(MoFlightChangeNoticeRequest moRequest) {
        MoFlightChangeNoticeResponse response = new MoFlightChangeNoticeResponse();
        moRequest.OnlyCode = strOnlyCode;

        response.OnlyCode = moRequest.OnlyCode;
        response.ProviderCode = moRequest.ProviderCode;
        response.RequestType = moRequest.RequestType;

        String strRequestData = "";
        String strResponseData = "";
        Date requestTime = new Date();

        //TODO 等待中 ...

        try {

            /*strRequestData = JSON.toJSONString(moRequest);
            if(Strings.isNullOrEmpty(moRequest.RequestData)){
                response.ErrorMsg = "接口返回参数为空" ; //EnumHelper.ReturnCode.接口返回参数为空.ToString();
                response.ErrorCode = "接口返回参数为空"; //((int)EnumHelper.ReturnCode.接口返回参数为空).ToString();
                return response;
            }*/


            //base64位解码
            String result = Base64.decode(moRequest.RequestData).toString();

            logger.info("base64转码结果为：{}", result);


            ChangeInfo ci = new ChangeInfo();


        } catch (Exception e) {

        }

        return response;
    }


    /**
     * 上传附件操作
     *
     * @param request
     * @return
     */
    @Override
    public MoAttachmentResponse _AddAttachment(MoAttachmentRequest request) {
        MoAttachmentResponse response = new MoAttachmentResponse();

        String strResponseXml = "";
        Date requestTime = new Date();


        try {

            MoQunar mo = new MoQunar("flight.national.supply.sl.tpUpload", requestTime.getTime());

            //此处的参数用于生成sign值
            Map<String, Object> map = new HashMap<>();
            map.put("orderNo", request.OrderId);
            map.put("passengerIds", request.OtherParams);

            //系统参数
            Map<String, Object> dic = new LinkedHashMap<>();
            String applyJson = JSON.toJSONString(map);
            dic.put("sign", _Qunar.getSing(mo.Token, mo.Tag, mo.CreateTime, applyJson, AppKey));
            dic.put("tag", mo.Tag);
            dic.put("token", mo.Token);
            dic.put("createTime", mo.CreateTime);
            dic.put("params", URLEncoder.encode(applyJson, "UTF8"));

            //拼接请求参数
            StringBuffer buffer = null;
            if (dic != null) {
                Iterator<String> it = dic.keySet().iterator();
                while (it.hasNext()) {
                    String key = it.next();
                    Object value = dic.get(key);
                    if (buffer == null) {
                        buffer = new StringBuffer();
                    } else {
                        buffer.append("&");
                    }
                    buffer.append(key);
                    buffer.append("=");
                    buffer.append(value);
                }
            }

            //处理乘机人id多个ID以逗号分隔
            StringBuffer bf = null;
            if (request.OtherParams.length() > 0 && request.OtherParams != null) {
                //多个乘机人id
                if (request.OtherParams.contains(",")) {
                    //根据,分割
                    String[] passengerIds = request.OtherParams.split(",");
                    for (String passengerId : passengerIds) {
                        if (bf == null) {
                            bf = new StringBuffer();
                        } else {
                            bf.append(",");
                        }
                        bf.append(passengerId);
                    }
                }
                //一个乘机人id
                else {
                    bf = new StringBuffer();
                    bf.append(request.OtherParams);
                }

            }


            //请求地址后边需要拼接 订单id、乘机人id
            String finalUrl = ServerUrl + "?" + buffer.toString() + "&orderNo=" + request.OrderId + "&passengerIds=" + bf.toString();


            // 创建Http Post请求
            CloseableHttpClient httpClient = HttpClients.createDefault();
            HttpPost httpPost = new HttpPost(finalUrl);

            MultipartFile file = null;  //TODO

            //上传的文件
            MultipartEntityBuilder builder = MultipartEntityBuilder.create();
            builder.addBinaryBody("file", file.getInputStream(), ContentType.create("image/*"),
                    file.getOriginalFilename());
            HttpEntity httpEntity = builder.build();
            httpPost.setEntity(httpEntity);

            // 执行http请求
            CloseableHttpResponse execute = httpClient.execute(httpPost);
            strResponseXml = EntityUtils.toString(execute.getEntity(), "utf-8");


            if (Strings.isNullOrEmpty(strResponseXml)) {
                response.ErrorCode = EnumHelper.ReturnCode.失败.toString();
                response.ErrorMsg = "上传附件图片失败";
                return response;
            }

            QunarTpUploadResponse res = JSON.parseObject(strResponseXml, QunarTpUploadResponse.class);

            if (!"上传成功".equals(res.result)) {
                response.ErrorCode = EnumHelper.ReturnCode.失败.toString();
                response.ErrorMsg = res.message;
                return response;
            }

            response.IsSuccess = true;

        } catch (Exception e) {
            response.IsSuccess = false;
            response.ErrorMsg = e.getMessage();
            response.ErrorCode = EnumHelper.ReturnCode.系统异常代码.toString();
        }
        return response;
    }


    /**
     * 报销详情接口
     *
     * @param orderNo
     */
    public void bxDetails(String orderNo) {

        String strResponseData = "";
        String strRequestData = "";
        Date requestTime = new Date();

        MoQunar mo = new MoQunar("flight.national.supply.sl.courierNumber", requestTime.getTime());

        Map<String, Object> applyData = new HashMap<>();
        applyData.put("orderNo", orderNo);

        try {
            strResponseData = _GetResponseData(mo, applyData, strRequestData);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    /**
     * 二次索要行程单接口
     */
    public void tripTwoQuery(String orderNo) {
        String strResponseData = "";
        String strRequestData = "";
        Date requestTime = new Date();

        MoQunar mo = new MoQunar("flight.national.supply.sl.itinerary.search", requestTime.getTime());

        Map<String, Object> applyData = new HashMap<>();
        applyData.put("orderNo", orderNo);

        try {
            strResponseData = _GetResponseData(mo, applyData, strRequestData);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


    /**
     * 改期查询
     *
     * @param
     * @param orderId
     * @param changeDepDate
     * @return
     */
    private QunarTgSearchResponse _ChangeSearch(String orderId, String changeDepDate) {

        QunarTgSearchResponse response = new QunarTgSearchResponse();

        String strRequestData = "";
        String strResponseData = "";
        Date requestTime = new Date();

        try {
            MoQunar mo = new MoQunar("flight.national.supply.sl.changeSearch", requestTime.getTime());

            //应用级参数
            Map<String, Object> applyData = new HashMap<>();
            applyData.put("orderNo", orderId); //订单号
            applyData.put("changeDate", changeDepDate); //改签日期

            //发送请求
            strResponseData = _GetResponseData(mo, applyData, strRequestData);

            if (Strings.isNullOrEmpty(strResponseData)) {
                response.code = EnumHelper.ReturnCode.接口返回参数为空.getValue();
                response.message = "改期查询，未返回数据";
                return response;
            }

            response = JSON.parseObject(strResponseData, QunarTgSearchResponse.class);

        } catch (Exception e) {
            response.code = EnumHelper.ReturnCode.系统异常代码.getValue();
            response.message = e.getMessage();

        }

        return response;
    }


    /**
     * 获取签名
     *
     * @param token
     * @param tag
     * @param createTime
     * @param param
     * @param key
     * @return
     */
    private static String getSing(String token, String tag, long createTime,
                                  String param, String key) {
        List<String> list = new ArrayList();
        list.add("token=" + token);
        list.add("tag=" + tag);
        list.add("createTime=" + createTime);
        list.add("params=" + param);
        list.add("key=" + key);
        //排序
        Collections.sort(list);

        //拼接
        StringBuffer buffer = new StringBuffer(512);
        for (String par : list) {
            buffer.append(par);
        }
        //md5加密并且小写
        String sign = md5(buffer.toString());
        return sign;
    }

    /**
     * md5加密
     *
     * @param sourceStr
     * @return
     */
    private static String md5(String sourceStr) {
        String md5Hex = DigestUtils.md5Hex(sourceStr.getBytes(StandardCharsets.UTF_8));
        return md5Hex;
    }

    private String data(Date date, String str) {
        SimpleDateFormat format = new SimpleDateFormat(str);
        return format.format(date);
    }

    private Date convertToDate(String str) {
        SimpleDateFormat sdf = new SimpleDateFormat();
        Date date = null;
        if (str != null) {
            try {
                date = sdf.parse(str);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return date;
    }


    /**
     * 根据格式拆分成字符串
     *
     * @param sources
     * @return
     */
    private String splitConvertString(String[] sources) {
        StringBuffer buffer = null;
        if (sources != null || sources.length > 0) {
            buffer = new StringBuffer();
            for (int i = 0; i < sources.length; i++) {
                buffer.append(sources[i]);
            }
        }
        return buffer.toString();

    }

    /**
     * 转换订单状态
     *
     * @param status
     * @return
     */
    private int _CnonvertOrderStatus(String status) {
        switch (status) {
            case "订座成功等待支付":
                return 101;
            case "支付成功等待出票":
                return 300;
            case "出票完成":
                return 301;
            case "出票中":
                return 303;
            case "订单取消":
                return 102;
            case "等待座位确认":
                return 100;
            case "退款待确认":
                return 400;
            case "待退款":
                return 402;
            case "退款完成":
                return 403;
            case "改签申请中":
                return 503;
            case "改签完成":
                return 501;
            case "未出票申请退款":
                return 401;
            case "订座成功等待价格确认":
                return 100;
            default:
                return 0;
        }

    }


    /**
     * 根据 BookingStatus获取描述
     *
     * @param status
     * @return
     */
    private String _ConvertBookingStatusMsg(String status) {
        String msg = "";
        switch (status) {
            case "BOOKING_SUCCESS":
                msg = "验价成功";
                break;
            case "BOOKING_PARAMETER":
                msg = "验价参数错误";
                break;
            case "TIME_OUT":
                msg = "验价超时";
                break;
            case "IBE_AV_NO_CABIN":
                msg = "仓位已售完";
                break;
            case "IBE_AV_NO_Y_CABIN":
                msg = "Y仓已售完";
                break;
            case "INTERFACE_EXCEPTION":
                msg = "验价接口异常";
                break;
            case "NO_PAY_INFO":
                msg = "暂无报价";
                break;
            case "ERROR_RESULT":
                msg = "结果出错";
                break;
            case "INVALID_REQUEST":
                msg = "非法请求";
                break;
            case "SEARCH_ERROR":
                msg = "搜索出错，请稍后再试";
                break;
            case "DUBBO_CALL_FAIL":
                msg = "验价失败";
                break;
            case "BOOKING_BEAN_SWITCH_FAIL":
                msg = "返回验价结果时失败";
                break;
            case "SEARCH_RESULT_ERROR":
                msg = "搜索结果无效";
                break;
            case "AV_CHANGE":
                msg = "搜索结果变化";
                break;
            case "GET_POLICY_FAIL":
                msg = "获取政策失败";
                break;
            case "MIAOSHA_ERROR":
                msg = "秒杀验价出错";
                break;
            case "BOOKING_ERROR":
                msg = "验价失败";
                break;
            case "BOOKING_REJECT":
                msg = "验价拒绝";
                break;
            case "PARAM_IS_EMPTY":
                msg = "验价参数为空";
                break;
            case "PARAM_INVALID":
                msg = "验价参数不合法";
                break;
            case "PARAM_EXCEPTION":
                msg = "验价参数异常";
                break;
            case "SYSTEM_EXCEPTION":
                msg = "验价系统异常";
                break;
            case "BOOKING_FAILURE":
            default:
                msg = "验价失败";
                break;
        }

        return String.format("%s (%s)", msg, status).trim();
    }

    /**
     * 转换退票类型
     *
     * @param nRefundType
     * @return
     */
    private int _ConvertRefundType(int nRefundType) {
        int nOutnRefundType = 18;

        //自愿
        if (nRefundType == 1) {
            nOutnRefundType = 16;
        }

        //其他非自愿 | 备降 | 重购全退
        if (nRefundType == 2 || nRefundType == 2003 || nRefundType == 2004) {
            nOutnRefundType = 18;
        }

        //病退
        if (nRefundType == 2002) {
            nOutnRefundType = 19;
        }

        //航班取消 | 航变
        if (nRefundType == 2006 || nRefundType == 2001) {
            nOutnRefundType = 18;
        }

        return nOutnRefundType;
    }

    /**
     * 发送请求
     *
     * @param mo             对象
     * @param applyData      应用参数
     * @param strRequestData 请求参数
     * @return
     */
    private String _GetResponseData(MoQunar mo, Object applyData, String strRequestData) throws URISyntaxException, IOException {
        String applyJson = JSON.toJSONString(applyData);
        Map<String, Object> dic = new LinkedHashMap<>();
        dic.put("sign", _Qunar.getSing(mo.Token, mo.Tag, mo.CreateTime, applyJson, AppKey));
        dic.put("tag", mo.Tag);
        dic.put("token", mo.Token);
        dic.put("createTime", mo.CreateTime);
        dic.put("params", URLEncoder.encode(applyJson, "UTF8"));
        //urlencode

        //拼接请求参数
        StringBuffer buffer = null;
        if (dic != null) {
            Iterator<String> it = dic.keySet().iterator();
            while (it.hasNext()) {
                String key = it.next();
                Object value = dic.get(key);
                if (buffer == null) {
                    buffer = new StringBuffer();
                } else {
                    buffer.append("&");
                }
                buffer.append(key);
                buffer.append("=");
                buffer.append(value);
            }
        }

        logger.info("===请求地址:{}", ServerUrl);
        logger.info("===请求参数：{}", buffer.toString());
        logger.info("===完整地址以及参数: {}", ServerUrl + "?" + buffer.toString());

        String response = HttpClientUtil.doGet(ServerUrl + "?" + buffer.toString());
        return response;
    }
}








